Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL error 2006: mysql server has gone away

I'm running a server at my office to process some files and report the results to a remote MySQL server.

The files processing takes some time and the process dies halfway through with the following error:

2006, MySQL server has gone away 

I've heard about the MySQL setting, wait_timeout, but do I need to change that on the server at my office or the remote MySQL server?

like image 752
floatleft Avatar asked Oct 29 '11 22:10

floatleft


People also ask

How do you fix 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.

How do you fix MySQL server has gone away?

Excerpt: “You can check whether the MySQL server died and restarted by executing mysqladmin version and examining the server's uptime. If the client connection was broken because mysqld crashed and restarted, you should concentrate on finding the reason for the crash.”

Why is MySQL not connecting to server?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.


1 Answers

I have encountered this a number of times and I've normally found the answer to be a very low default setting of max_allowed_packet.

Raising it in /etc/my.cnf (under [mysqld]) to 8 or 16M usually fixes it. (The default in MySql 5.7 is 4194304, which is 4MB.)

[mysqld] max_allowed_packet=16M 

Note: Just create the line if it does not exist

Note: This can be set on your server as it's running.

Note: On Windows you may need to save your my.ini or my.cnf file with ANSI not UTF-8 encoding.

Use set global max_allowed_packet=104857600. This sets it to 100MB.

like image 130
George Avatar answered Oct 12 '22 11:10

George