Databases

How to fix "MySQL server has gone away" (error 2006)

Getting "MySQL server has gone away" during imports or long scripts? Learn the causes, from max_allowed_packet and timeouts to crashed servers, and how to fix error 2006.

IntermediatecPanel hosting and VPS2 min read

The error "MySQL server has gone away" (error 2006, sometimes with 2013 "Lost connection to MySQL server during query") means the connection between your application and the database closed unexpectedly. It shows up during large imports, long-running scripts and cron jobs, and occasionally when the database server restarts.

Before you start

  • Note when it happens: importing a dump, running a long script, or randomly on the site.
  • Access to phpMyAdmin or SSH.

Common causes of error 2006

  • A packet larger than max_allowed_packet – big INSERT statements or blobs in an import.
  • Idle connection timeout – the script kept the connection open but idle past wait_timeout.
  • The MySQL server restarted or crashed, for example killed for low memory on a VPS.
  • Large imports through phpMyAdmin hitting web timeouts.

Fix it on cPanel hosting

  1. Import large dumps in smaller parts, or use mysql over SSH: mysql -u dbuser -p dbname < backup.sql.
  2. Export with smaller statements: when creating the dump, use the option to limit extended inserts so no single statement is huge.
  3. Reconnect in scripts: long PHP jobs should reconnect before queries after long pauses, or process data in batches.
  4. Contact support if normal page loads show the error; the database server may need checking.

Fix it on a VPS

  1. Raise limits in /etc/my.cnf or /etc/mysql/my.cnf under [mysqld]:
    max_allowed_packet=256M
    wait_timeout=600
  2. Restart MySQL/MariaDB and confirm with SHOW VARIABLES LIKE 'max_allowed_packet';.
  3. Check if MySQL crashed: journalctl -u mariadb -n 100 or the MySQL error log, and dmesg | grep -i kill for the OOM killer. See OOM killer.

Tip: For WordPress site moves, migration plugins or WP-CLI (wp db import) handle large databases far more reliably than phpMyAdmin uploads.

FAQ

Is my data lost after "server has gone away"?

No, but an interrupted import may be incomplete. Re-run it on an empty database.

Can I change max_allowed_packet on shared hosting?

Not at server level; split the import or use smaller statements instead.

What is the difference between 2006 and 2013?

Both mean the connection dropped: 2006 when sending, 2013 during a query.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.