2006ERRORTier 1 — Safe✅ HIGH confidenceMySQL server has gone away
🔴 Production Risk Error
HIGH — causes query failures in long-running or pooled applications.
What this means
Client error 2006 is returned when the server closes the connection while the client still has it open. This is typically caused by the connection being idle longer than wait_timeout, a query result larger than max_allowed_packet, or the server being restarted.
Why it happens
- 1Connection was idle longer than wait_timeout (default 8 hours) and the server dropped it
- 2Query or result set exceeds max_allowed_packet — server closes connection on oversized packet
- 3Server was restarted while the connection was open
- 4Network interruption between client and server
- 5Application is reusing a connection from a pool that was silently closed by the server
How to reproduce
Executing a query on a connection that the server has already closed.
-- After a long idle period:
SELECT * FROM large_table;Fix 1: Increase wait_timeout and interactive_timeout
When connections are legitimately idle for extended periods.
SET GLOBAL wait_timeout = 28800; -- 8 hours
SET GLOBAL interactive_timeout = 28800;
-- Permanent setting in my.cnf:
-- wait_timeout = 28800Why this works
wait_timeout controls how long the server keeps an idle non-interactive connection alive. Raising it reduces the frequency of disconnects for long-running application processes.
Fix 2: Enable connection pool reconnection / ping
In applications using a connection pool (most frameworks).
-- PDO example — enable persistent connections with ping:
$pdo = new PDO($dsn, $user, $pass, [
PDO::ATTR_PERSISTENT => true,
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
]);
-- Most ORMs have a reconnect option; enable it.Why this works
Connection pools should validate (ping) connections before reuse. MariaDB Connector/J, MySQL Connector/J, and most ORMs support automatic reconnection.
Fix 3: Increase max_allowed_packet for large queries
When the error occurs with large INSERT or BLOB operations.
SET GLOBAL max_allowed_packet = 67108864; -- 64 MB
-- Permanent in my.cnf:
-- max_allowed_packet = 64MWhy this works
max_allowed_packet limits the maximum size of one network packet. Queries or results larger than this cause the server to drop the connection.
What not to do
Set wait_timeout to a very high value to mask connection leaks
Why it's wrong: Idle connections consume server resources and thread slots; fix pool configuration instead.
Sources
📚 Official docs: https://mariadb.com/kb/en/server-system-variables/#wait_timeout
🔧 Source ref: MySQL Client error 2006 / CR_SERVER_GONE_ERROR
📖 Further reading: MariaDB wait_timeout
📖 Further reading: MariaDB max_allowed_packet
Confidence assessment
✅ HIGH confidence
Stable.
See also
🔗 Related errors
📄 Reference pages