How do I fix the "MySQL server has gone away" error?

Linode Staff

I'm frequently receiving the error "MySQL server has gone away" how can I fix this?

1 Reply

The type of error you're receiving can be caused mainly by two things. The first cause can be your server timing out and closing the connection, the second can be your server dropped a packet that was incorrect or too large. We'll go over how to adjust some values in your MySQL configuration files to correct these issues.

In order to fix your server timing out and closing your connection, you'll want to check that the wait_timeout variable in your my.cnf file is large enough. This sets the time the server waits for activity on a non-interactive connection before closing it. If you're unfamiliar with this variable you can learn more about it through the MySQL Reference Manual.

You may also need to increase the log file size by increasing the innodb_log_file_size variable in your my.cnf file. The default value is 48 MB, the value you'll want to increase it to will depend on what you use your server for. Something to keep in mind, setting this to a large value can lead to long recovery times after a crash.

The most common fix for this error is increasing the max_allowed_packet variable in your my.cnf file. The default value for this is 4 MB, increasing this value to 128 MB should reduce server drops due to a too large packet. You ant to restart your MySQL server after making this change using /etc/init.d/mysql restart. I also found thisStack Overflow post covering this topic and most users had success by increasing the max_allowed_packet variable.

I hope this information helps! If there is anything I may have missed, feel free to leave a reply.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct