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– bigINSERTstatements 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
- Import large dumps in smaller parts, or use
mysqlover SSH:mysql -u dbuser -p dbname < backup.sql. - Export with smaller statements: when creating the dump, use the option to limit extended inserts so no single statement is huge.
- Reconnect in scripts: long PHP jobs should reconnect before queries after long pauses, or process data in batches.
- Contact support if normal page loads show the error; the database server may need checking.
Fix it on a VPS
- Raise limits in
/etc/my.cnfor/etc/mysql/my.cnfunder[mysqld]:max_allowed_packet=256M wait_timeout=600 - Restart MySQL/MariaDB and confirm with
SHOW VARIABLES LIKE 'max_allowed_packet';. - Check if MySQL crashed:
journalctl -u mariadb -n 100or the MySQL error log, anddmesg | grep -i killfor 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.
