MySQL ERROR 2006: server has gone away - Rocketeers

 On this page

 Knowledge
---------

MySQL ERROR 2006: server has gone away
======================================

### [\#Databases](http://rocketee.rs/index.php/databases)

This error means the connection to MySQL was lost mid-query. The usual causes are an idle timeout, a query larger than max\_allowed\_packet, or the server restarting.

 Published by Mark van Eijk on June 23, 2026 · 1 minute read

1. [About the error](#content-about-the-error)
2. [Why do I see this error](#content-why-do-i-see-this-error)
3. [Solution](#content-solution)
4. [Idle timeout](#content-idle-timeout)
5. [Oversized query](#content-oversized-query)
6. [Server restarted](#content-server-restarted)

[\#](#content-about-the-error "Permalink")About the error
---------------------------------------------------------

 ```
ERROR 2006 (HY000): MySQL server has gone away

```

It means the client sent a query but the connection to the server was already closed or dropped. The message is generic, MySQL is telling you the link is gone, not why.

[\#](#content-why-do-i-see-this-error "Permalink")Why do I see this error
-------------------------------------------------------------------------

Three causes account for almost every case:

- **Idle timeout**: the connection sat idle longer than `wait_timeout` and MySQL closed it. Common with long-running queue workers and scheduled jobs.
- **Oversized query**: a single statement exceeded `max_allowed_packet`, so the server dropped the connection. See [MySQL max\_allowed\_packet: packet too large](/mysql-max-allowed-packet-packet-too-large).
- **The server restarted or was OOM-killed** while the client held a connection.

[\#](#content-solution "Permalink")Solution
-------------------------------------------

### [\#](#content-idle-timeout "Permalink")Idle timeout

If the error happens after periods of inactivity, raise the idle timeout in `my.cnf`:

 ```
[mysqld]
wait_timeout = 600
interactive_timeout = 600

```

Then restart MySQL. For a long-running PHP worker, the more robust fix is to **reconnect** rather than hold one connection open for hours. In Laravel, a queue worker that reconnects on each job avoids the problem; you can also have the worker restart periodically:

 ```
php artisan queue:work --max-time=3600

```

### [\#](#content-oversized-query "Permalink")Oversized query

If it happens on a specific large insert or import, the packet limit is the cause, not the timeout. Raise it on both server and client:

 ```
[mysqld]
max_allowed_packet = 256M

```

See the dedicated [max\_allowed\_packet article](/mysql-max-allowed-packet-packet-too-large) for the full walkthrough.

### [\#](#content-server-restarted "Permalink")Server restarted

If neither applies, check whether MySQL crashed or was killed. Look at the MySQL error log and the system journal:

 ```
sudo tail -n 50 /var/log/mysql/error.log
sudo journalctl -u mysql --since "1 hour ago"

```

An out-of-memory kill points at server sizing, see [adding swap space on Ubuntu](/add-swap-space-on-ubuntu).

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### Related articles

[Stream MySQL backup directly to S3 bucket](http://rocketee.rs/index.php/stream-mysql-backup-s3-bucket)
-------------------------------------------------------------------------------------------------------

This error means the connection to MySQL was lost mid-query. The usual causes are an idle timeout, a query larger than max\_allowed\_packet, or the server restarting.

[Read more →](http://rocketee.rs/index.php/stream-mysql-backup-s3-bucket)

[Export MySQL database using command line](http://rocketee.rs/index.php/export-database-mysql-command-line)
-----------------------------------------------------------------------------------------------------------

This error means the connection to MySQL was lost mid-query. The usual causes are an idle timeout, a query larger than max\_allowed\_packet, or the server restarting.

[Read more →](http://rocketee.rs/index.php/export-database-mysql-command-line)
