Download

ERROR 2006 (HY000): MySQL server has gone away

Your client sent a statement on a connection the server had already closed. Usually it sat idle longer than wait_timeout (8 hours by default); otherwise the statement was over max_allowed_packet, someone killed the connection, or the server restarted. Reconnect, and find out which.

MySQL error 2006· Tested on MySQL 8.4.11 and MariaDB 11.4.13 servers and clients· Updated 11 October 2026

ERROR 2006 (HY000): Server has gone away

What it means

Error 2006 comes from the client: it tried to send a statement and found that the server had closed the connection. The statement didn’t run. Nothing is wrong with the statement itself (unless it was too big, below); the connection was gone before it arrived.

The same event has several names, depending on the client and the moment it notices:

You seeFrom
2006 MySQL server has gone awayMany language drivers (PHP, Python, Ruby…) and older mysql clients
2006 Server has gone awayThe MariaDB client
4031 The client was disconnected by the server because of inactivityMySQL 8.0.24 and later, sent as it closes an idle connection
2013 Lost connection to MySQL server during queryThe MySQL 8.4 client, for most of the cases below

If the connection drops while a statement runs, see Lost connection to MySQL server during query.

Common causes

  1. The connection was idle longer than wait_timeout, 28,800 seconds (8 hours) by default, or than a proxy’s or load balancer’s idle timeout, which can be much shorter. A connection pool, a long-running script or a laptop that slept keeps a connection the server has since closed.
  2. The statement was bigger than max_allowed_packet: the server rejects it and closes the connection, and some clients only report the closed connection. See packet bigger than max_allowed_packet.
  3. The connection was killed: KILL, an administrator ending sessions, or a tool that kills long-idle ones.
  4. The server restarted or crashed, or failed over to another host.
  5. A firewall, load balancer or NAT dropped an idle TCP connection without telling either side.
  6. Several processes sharing one connection, such as an application that opens a connection and then forks workers.

How to fix it

Find out which

On the server, check the timeouts and how long it has been up:

SELECT @@wait_timeout, @@interactive_timeout, @@max_allowed_packet;
SHOW GLOBAL STATUS LIKE 'Uptime';
SHOW GLOBAL STATUS LIKE 'Aborted_clients';

An Uptime shorter than the connection’s age means a restart. Aborted_clients counts connections the server closed without the client saying goodbye, idle timeouts included. The error log can give the reason for each one (by default on MariaDB; on MySQL with log_error_verbosity at 3):

[Warning] Aborted connection 9 to db: 'shop' user: 'root' host: 'localhost' (Got a packet bigger than 'max_allowed_packet' bytes)

Reconnect, and check connections before use

Applications should expect connections to be closed. Most pools can test a connection before handing it out, or retire it before the server would: set the pool’s maximum idle time or lifetime below wait_timeout (and below any proxy’s idle timeout). In a long script, reconnect on 2006 and 2013 and retry the statement if it’s safe to repeat.

Raise wait_timeout, if idle connections should live longer

For one session:

SET SESSION wait_timeout = 28800;

For everyone, an administrator sets it in the configuration (wait_timeout under [mysqld]), or in a hosted database’s parameter settings. Longer timeouts keep more idle connections open, which counts against max_connections.

Big statements

If the error comes right after a large INSERT or an import, raise max_allowed_packet or send smaller statements, as described on the max_allowed_packet page.

Reproduce it

On the shared servers, as an ordinary account, with the session’s timeout shortened:

SET SESSION wait_timeout = 2;
-- wait 4 seconds
SELECT 2;

The mariadb client, against MariaDB 11.4.13:

ERROR 2006 (HY000): Server has gone away
No connection. Trying to reconnect...
Connection id:    198223
Current database: seo_err_mysql

It then ran the statement on the new connection. The mysql client, against MySQL 8.4.11, got the server’s own error first, then reconnected the same way:

ERROR 4031 (HY000): The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.
No connection. Trying to reconnect...

Run from a script (no reconnect), the statement after that got ERROR 2013 (HY000): Lost connection to MySQL server during query. The MySQL client also reported 2013, not 2006, when an idle connection was killed with KILL or the server was restarted under it, and against a MariaDB server’s idle timeout. The MySQL manual notes that which of the two numbers you get depends on the operating system.

In temporary containers with max_allowed_packet at 1 MB (removed afterwards), a 2 MB INSERT from the mariadb client gave ERROR 2006 (HY000): Server has gone away for it and the next statement, while the mysql client showed the underlying 1153.

In Inlet

When the server closes a connection, Inlet shows the server’s message (MySQL’s inactivity error, for instance), or “The server closed the connection” when there wasn’t one, and links to this page. Inlet’s Activity monitor for MySQL and MariaDB lists the server’s sessions, which shows how many idle connections your applications keep open.

Inlet: a database client for the Mac

One native app for PostgreSQL, MySQL, SQL Server, SQLite, MongoDB and Redis. It explains errors where they happen, holds your edits until you save them, and keeps production read-only until you say so.

Version 0.1.0 · macOS 26 Tahoe or later · Apple silicon and Intel