How to Fix the “MySQL Server Has Gone Away” Error
The "MySQL server has gone away" error means your site's connection to the database was lost mid-request — usually because a query took too long, was too large, or the connection sat idle and timed out. It sounds dramatic, but the causes are ordinary and fixable.
The common causes
- A query that ran too long and hit a timeout.
- A very large query or import exceeding the allowed packet size.
- An idle connection that timed out and was closed.
- The database being briefly overloaded under heavy use.
If it happens during an import
Large database imports are the classic trigger, because a big single query can exceed the server's packet limit. The reliable fix is to import over the command line via SSH, or to split the file into smaller parts — see importing a database.
If it happens on a live site
- Optimise slow queries and tables — see optimising your database.
- Add caching so the database is queried less — see Redis object caching.
- Check for overload in your resource usage.
If a table is corrupted
Occasionally the error accompanies a damaged table. Try repairing the database via phpMyAdmin.
Frequently asked questions
It only happens when I import a big SQL file.
That points to the packet-size limit on large queries. Import via SSH with the command line, which handles big files gracefully, or break the file into smaller chunks.
My site shows it randomly under load.
Random occurrences under traffic suggest the database is overloaded or connections are timing out. Add caching, optimise your queries, and check whether you are hitting resource limits.
Can I change the timeout or packet size myself?
On shared hosting these server-level values are managed for you. If your workload genuinely needs higher limits, open a support ticket and we will advise the best approach or plan.
Was this article helpful?