MySQL Server Has Gone Away

Understand and resolve MySQL connection losses.

The "MySQL server has gone away" error occurs when the connection between your application and MySQL is cut. This can happen for several reasons, each with different solutions.

Symptoms

Common Causes

Diagnostic Steps

  1. Check if MySQL is running (systemctl status mysql)
  2. Examine MySQL logs (/var/log/mysql/error.log)
  3. Check wait_timeout and max_allowed_packet
  4. Test with a simple query to isolate the problem

Automate with MoniTao

MoniTao helps detect these issues:

Best Practices

FAQ

What value for wait_timeout?

Default 28800s (8h). Reduce to 300s if you have many connections.

How to enable auto-reconnect?

In PHP with PDO, use ATTR_PERSISTENT or catch the error to reconnect.

max_allowed_packet, what value?

Minimum 16M for standard apps. 64M or more if you store blobs.

How does MoniTao help?

By monitoring endpoints, you detect when the DB has problems.

Ready to Sleep Soundly?

Start free, no credit card required.