// MySQL error reference

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
Error message
MySQL server has gone away

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_timeout or interactive_timeout.
  • A query or INSERT with a large BLOB or a big multi-row statement exceeded max_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

  1. Check the server's limits.

    SHOW VARIABLES WHERE Variable_name IN ('wait_timeout', 'interactive_timeout', 'max_allowed_packet');
  2. If large statements are the cause, raise max_allowed_packet on 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
  3. 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.

  4. Read the server error log around the time of the failure to rule out a crash or restart.

Related errors

More connection and client errors

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.

// fewer errors, faster fixes

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.