Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR 2006 (HY000): MySQL server has gone away

Tags:

mysql

I get this error when I try to source a large SQL file (a big INSERT query).

mysql>  source file.sql ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id:    2 Current database: *** NONE ***  ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id:    3 Current database: *** NONE *** 

Nothing in the table is updated. I've tried deleting and undeleting the table/database, as well as restarting MySQL. None of these things resolve the problem.

Here is my max-packet size:

+--------------------+---------+ | Variable_name      | Value   | +--------------------+---------+ | max_allowed_packet | 1048576 | +--------------------+---------+ 

Here is the file size:

$ ls -s file.sql  79512 file.sql 

When I try the other method...

$ ./mysql -u root -p my_db < file.sql Enter password:  ERROR 2006 (HY000) at line 1: MySQL server has gone away 
like image 357
bgcode Avatar asked May 06 '12 22:05

bgcode


People also ask

How do I fix error code 2006 MySQL server has gone away?

The MySQL server has gone away (error 2006) has two main causes and solutions: Server timed out and closed the connection. To fix, check that wait_timeout mysql variable in your my. cnf configuration file is large enough, eg wait_timeout = 28800.

What causes MySQL server has gone away?

The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection. In this case, you normally get one of the following error codes (which one you get is operating system-dependent). The client couldn't send a question to the server.

How do I fix error HY000?

To resolve the MySQL ERROR 1819 (HY000) error, set a lower password validation policy as shown. mysql> SET GLOBAL validate_password_policy=LOW; OR mysql> SET GLOBAL validate_password_policy=0; You can thereafter confirm the password validation policy level.


2 Answers

max_allowed_packet=64M 

Adding this line into my.cnf file solves my problem.

This is useful when the columns have large values, which cause the issues, you can find the explanation here.

On Windows this file is located at: "C:\ProgramData\MySQL\MySQL Server 5.6"

On Linux (Ubuntu): /etc/mysql

like image 200
Kurt Zhong Avatar answered Oct 19 '22 10:10

Kurt Zhong


You can increase Max Allowed Packet

SET GLOBAL max_allowed_packet=1073741824; 

http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_max_allowed_packet

like image 20
Nanhe Kumar Avatar answered Oct 19 '22 10:10

Nanhe Kumar