MySQL Error 2006: MySQL Server Has Gone Away
Fix MySQL Error 2006 by checking idle connection timeouts, max_allowed_packet, server restarts, and stale application connections.
On this page
MySQL client Error 2006 (HY000, CR_SERVER_GONE_ERROR) means the client tried to send a request after its connection to the server was no longer usable. The message is MySQL server has gone away. It does not by itself prove that the server process crashed. The MySQL 8.4 client error reference identifies the code, and the troubleshooting guide lists common causes.
First determine whether the server restarted, the connection expired while idle, or the request exceeded a connection limit. The safe fix depends on which of these happened.
Check whether MySQL restarted or closed the connection
Ask the database administrator to check the MySQL error log and uptime around the failure. A server crash, restart, administrator-issued KILL, or network interruption can invalidate connections held by an application pool. If the server restarted, investigate the log entry that explains why instead of repeatedly retrying the same request.
The MySQL command-line client can reconnect automatically in some cases, but application connectors differ. After a lost connection during a write, do not blindly retry a non-idempotent statement: the server may have completed the change even if the client did not receive the response. Check the transaction or application state first.
Refresh connections that sat idle too long
MySQL commonly closes a connection after it has been idle longer than wait_timeout. Check the server setting:
SHOW GLOBAL VARIABLES LIKE 'wait_timeout';
SHOW GLOBAL VARIABLES LIKE 'interactive_timeout';
For pooled connections, configure the application to validate or refresh a connection before reusing it, or set the pool’s idle lifetime below the server timeout. Raising the global timeout without understanding connection counts and server capacity can keep unnecessary sessions open; coordinate any server setting change with the database administrator. See the MySQL 8.4 wait_timeout documentation.
Check packet limits for large statements or results
Large BLOB values, a very large query, or an oversized multi-row INSERT can exceed max_allowed_packet. An administrator can compare the server setting with the client’s configuration:
SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet';
Reduce batch sizes or split large payloads when possible. If the application genuinely needs larger packets, coordinate compatible client and server limits with the administrator rather than raising them blindly. See the MySQL 8.4 max_allowed_packet documentation.
Error 2006 versus Errors 2013 and 2003
- Error 2006 (
CR_SERVER_GONE_ERROR): the client could not send a request on a connection that had become unusable. - Error 2013 (
CR_SERVER_LOST): the client lost the connection before receiving a complete response to a query. - Error 2003 (
CR_CONN_HOST_ERROR): the client could not establish a connection to the server and port; see MySQL Error 2003 troubleshooting.
For steps specific to connection loss during a query, see MySQL Error 2013 troubleshooting.
For related connection failures, see MySQL Error 2002 and the MySQL error troubleshooting index.