Why do you get the error “MySQL server has gone away”?

Getting the error “MySQL server has gone away”? It can have several causes, but they all share the same underlying issue: the connection to the database server closed unexpectedly.

A packet sent to the server was too large

A database server has a limit on how large a packet you can send it. The exact value is set by the server administrator – with us, it’s 10 MB.

Most of the time this limit won’t affect you, but storing files in the database can trigger this error. You shouldn’t store ordinary files in the database anyway – keep them alongside your website files instead, and store the file path in the database if needed.

This error can also come from large INSERT or REPLACE queries. Try splitting them into smaller batches instead of running everything at once.

The server timed out

A common cause is the server reaching its timeout limit and closing the connection. This can happen with systems that send newsletters or similar, since such scripts often run long enough to lose the database connection while running.

This timeout is also a server-side setting decided by the administrator. With us, it’s set to 60 seconds, meaning the server closes the connection after 60 seconds of inactivity.

Some less common causes

A few other things can trigger this error message, though they’re rare.

You might see it if the database server administrator has cancelled a query with the KILL command. This happens very rarely, and if we ever take such action, we contact the affected customer about what happened and how to resolve it.

If you query the database after already closing the connection, that naturally won’t work, and can produce an error like “MySQL server has gone away.”

The error can also appear during disruptions in the underlying network. This is unlikely with us, since we have good capacity and constant monitoring across our whole network.

Third-party applications

If you haven’t written the code running your site yourself, and haven’t hired a developer or agency, troubleshooting can be trickier. Start by checking whether there are updates available for the application you’re running (such as WordPress, Joomla or Zencart).

If you’re already on the latest version, check whether the application’s documentation covers the error, or search for the error together with the application’s name.

Still stuck?

If you’re still unable to resolve the issue, feel free to contact our support and we’ll take a look at what might be causing it. Note that we don’t offer scripting support, and such cases are handled as time allows.

Was this article helpful?

Related Articles