MySQL error 2006: MySQL server has gone away
The connection was closed before or while the client sent a command: an idle timeout, a packet bigger than max_allowed_packet, or a server restart.
- Error number
2006- Name
CR_SERVER_GONE_ERROR- Category
- Connection and client
What it means
The client tried to use a connection the server had already closed. MySQL closes connections that sit idle longer than wait_timeout (8 hours by default), kills connections that send a packet larger than max_allowed_packet, and drops all of them when it restarts or crashes.
The statement you just sent didn't run, unless the connection dropped while it was running, in which case you may see 2013 instead.
Common causes
- An application or pool kept a connection idle longer than
wait_timeoutorinteractive_timeout. - A query or
INSERTwith a large BLOB or a big multi-row statement exceededmax_allowed_packet. - The server restarted, ran out of memory, or the connection was killed with
KILL. - A proxy, load balancer or firewall dropped an idle TCP connection.
How to fix it
-
Check the server's limits.
SHOW VARIABLES WHERE Variable_name IN ('wait_timeout', 'interactive_timeout', 'max_allowed_packet'); -
If large statements are the cause, raise
max_allowed_packeton the server (and in the client, which has its own limit).SET GLOBAL max_allowed_packet = 64 * 1024 * 1024; -- new connections only; also set it in my.cnf
-
In applications, let the pool validate or recycle connections before
wait_timeout(for example a max lifetime a little below it), and reconnect and retry when a connection turns out to be dead. -
Read the server error log around the time of the failure to rule out a crash or restart.
Related errors
2013Lost connection to MySQL server during query1153Got a packet bigger than max_allowed_packet4031Disconnected by the server for inactivity2055Lost connection to MySQL server at stage08006PostgreSQL: connection failureORA-03113Oracle: end-of-file on communication channel
More connection and client errors
2002Can't connect through socket2003Can't connect to MySQL server on host2005Unknown MySQL server host2026SSL connection error2059Authentication plugin cannot be loaded2061Authentication plugin reported error1251Client doesn't support auth protocol3159Insecure transport prohibited
The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.
Work on MySQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.