“MySQL server has gone away” while importing SQL and Dump

When you try to import a large SQL file to your MySQL database but midway through the process, it shows this error:

“General error: 2006 MySQL server has gone away“

Like it just goes out for a cup of tea, and then the only thing you want in the world is for it to come back.

MySQL server has gone away

There are two reasons for that error:

  • The server timed out and closed the connection.
  • The server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection.

And there’re two things you can do to fix it:

1. Increase wait_timeout.

  • To see the current value, run this command:
SELECT @@wait_timeout;
  • From your client, execute this command to set a higher value for wait_timeout:
SET GLOBAL wait_timeout=600;
  • You can also fix it by changing the limit [wait_timeout] mysql variable in your my.cnf configuration file. Usually it’s located in /etc/mysql/my.cnf.

Then restart the server and try importing again.

2. Increase max_allowed_packet

the max_allowed_packet variable is the maximum size of one packet or any generated/intermediate string or any parameter sent by the mysql_stmt_send_long_data() C API function. The minimum value is 1024 and the maximum value is 107374182. This value by default is small, to catch large or incorrect packets.

  • To see the current value:
SELECT @@max_allowed_packet;
  • From your client side, increase the global value of max_allowed_packetby running this command after logging in to the root account:
SET GLOBAL max_allowed_packet=a-big-size

Replace a-big-size with a bigger value, 107374182 for example.

  • Or you can edit the MySQL configuration file my.cnf with this line:

Then restart the server and try importing again.

Leave a Comment

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

Scroll to Top