mysqldude
Error codes › 2006

MySQL & MariaDB error 2006: MySQL server has gone away

MySQLMySQL server has gone away
MariaDBServer has gone away
Example from our test runs: MySQL server has gone away (5.6.51) · Server has gone away (10.6.28)

The client tried to use a connection the server had already closed. Usually an idle timeout, a packet bigger than max_allowed_packet, or a server restart.

MySQLMariaDB
SymbolCR_SERVER_GONE_ERRORCR_SERVER_GONE_ERROR
SQLSTATEHY000HY000
TypeClient library errorClient library error
Versionsevery release since 5.0 activesince 10.2.44 active

What it means

The connection was closed before the client sent its statement (or while sending it). The client only finds out when it tries to write, hence “has gone away”. 2013 is the same family, raised when the drop happens while waiting for a result.

Why it happens

  • Idle timeout: the connection was unused for longer than wait_timeout (default 28,800 seconds, often lowered by hosting providers to 60–300). MySQL 8.0.24+ reports this case as 4031 when it can.
  • Packet too large: a single statement or row bigger than max_allowed_packet. MySQL 8.0+ clients now report this case clearly as 1153; MySQL 5.x and MariaDB still show 2006, as our tests confirm (4 MB by default on MySQL 5.6/5.7, 64 MB on 8.0, 16 MB on MariaDB). The server drops the connection instead of reading it: typical with big BLOBs, multi-row INSERTs and mysqldump restores. See 1153.
  • The server was restarted or crashed in between.
  • A firewall or NAT gateway silently dropped an idle TCP connection.

How to fix it

  • Large statements: raise max_allowed_packet on the server (SET GLOBAL max_allowed_packet = 67108864; and in my.cnf) and in the client (mysql --max-allowed-packet=64M, or the driver setting). For dumps, split them with mysqldump --net-buffer-length / --skip-extended-insert.
  • Idle connections: reconnect or validate before use (connection pools have a test-on-borrow setting), or raise wait_timeout for that client.
  • Check the server error log for restarts or crashes.

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database and the test data:

    CREATE DATABASE demo;
    USE demo;
    CREATE TABLE big (b LONGBLOB);
  2. As an admin, lower the limit to 1 MB (new connections pick it up).

    SET GLOBAL max_allowed_packet = 1048576;
  3. Reconnect and send a statement of about 3 MB, for example from a shell:

    { printf "INSERT INTO big VALUES ('"; head -c 3000000 /dev/zero | tr '\0' a; printf "');\n"; } | mysql -u root -p demo
  4. Put the limit back afterwards (64 MB is the MySQL 8.0 default).

    SET GLOBAL max_allowed_packet = 67108864;

You get: ERROR 2006 (HY000) at line 1: Server has gone away(11.8.9)

Verified fixes

  1. Raise max_allowed_packet above the largest row or statement you send

    Raise the server limit (and put it in my.cnf under [mysqld] so it survives a restart).

    SET GLOBAL max_allowed_packet = 67108864;  -- 64 MB

    Reconnect with a matching client limit and send the statement again.

    mysql -u root -p --max-allowed-packet=64M demo < big-insert.sql

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
Send a statement bigger than max_allowed_packet (the server drops the connection)
repro
✓ 2006✓ 2006✓ 1153✓ 1153✓ 1153✓ 2006✓ 2006✓ 2006✓ 2006
Raise max_allowed_packet above the largest row or statement you send
fix
✓✓✓✓✓✓✓✓✓
Send a statement bigger than max_allowed_packet (the server drops the connection) repro
MySQL 5.6✓ 20065.7✓ 20068.0✓ 11538.4✓ 11539✓ 1153
MariaDB 10.6✓ 200610.11✓ 200611.4✓ 200611.8✓ 2006
Raise max_allowed_packet above the largest row or statement you send fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9

Related errors

  • 2013 CR_SERVER_LOSTexplained
  • 4031 ER_CLIENT_INTERACTION_TIMEOUTexplained
  • 1153 ER_NET_PACKET_TOO_LARGEexplained
How the message changed between versions
MySQL fromSymbolMessage
5.0.96CR_SERVER_GONE_ERRORMySQL Server nicht vorhanden
5.5.63CR_SERVER_GONE_ERRORMySQL server has gone away