How to troubleshoot the “MySQL server has gone away” error

If you found this post helpful, kindly share it and show your support :)

The MySQL server has gone away error denotes that the connection was closed by the MySQL server (mysqld) after it timed out. If nothing happens for eight hours (28800 seconds), MySQL will automatically terminate all open connections. It’s possible that your web host, DBA, or app developer reduced this timeout setting in some circumstances, as will be covered in the section that follows.

When attempting to restore a database, you might encounter the “MySQL Server has gone away” error.

# mysql database_name < database_back.sql
ERROR 2006 (HY000) at line 1253: MySQL server has gone away

Here are some instances of the error “MySQL server has gone away” from error logs:

Error Code: 2013. Lost connection to MySQL server during query

Warning: Error while sending QUERY packet

PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

The followings are the primary causes of these errors and their fixes:-

  • The connection was terminated by the server because it ran out of time. Verify that the wait timeout MySQL variable in your my.cnf configuration file is large enough to handle the situation.
  • The InnoDB log file size MySQL variable in your my.cnf configuration might also need to be increased, perhaps to 128MB or higher.
  • When a packet was too big or incorrect, the server dropped it. When mysqld receives a packet that is too large or incorrect, it assumes that the client is at fault and cuts off the connection.

The packet size in the my.ini file needs to be increased as a fix. 1 MB is the default. Change it to a value like 24M.


Add max allowed packet after [mysqld] if it doesn’t already exist. Remember to save the file. You must restart MySQL for the changes to take effect after changing (or adding) the max allowed packet.

That’s it 🙂


Mohammed Noufal

I'm Mohammed Noufal, working as Server Admin for the last 10 years.  In my day-to-day life, l had to face different problems related to Web-hosting. On my website, you can find solutions for different Web-hosting-related problems. Sometimes, I spent hours searching/googling to find a solution. This inspired me to start a website that gives solutions to different Webhosting problems. This website includes basic Linux and windows commands, and different control panels like cPanel, Plesk, DirectAdmin, Webmin & so on. You can find solutions and or suggestions for different Web-hosting related problems from here. Hence I would like to say Errorlogz is your server protector.  I will be glad if Logdetect can help any one of the Server admins to find a solution to his problem.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *