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?
It was RAM problem for me.
I was having the same problem even on a server with 12 CPU cores and 32 GB RAM. I researched more and tried to free up RAM. Here is the command I used on Ubuntu 14.04 to free up RAM:
And, it fixed everything. I have set it under cron to run every hour.
And, you can use this command to check how much free RAM available:
And, you will get something like this:
I had the same problem but changeing
max_allowed_packet
in themy.ini/my.cnf
file under[mysqld]
made the trick.add a line
now
restart the MySQL service
once you are done.Error: 2006 (CR_SERVER_GONE_ERROR)
Generally you can retry connecting and then doing the query again to solve this problem - try like 3-4 times before completely giving up.
I'll assuming you are using PDO. If so then you would catch the PDO Exception, increment a counter and then try again if the counter is under a threshold.
If you have a query that is causing a timeout you can set this variable by executing:
Where 300 is the number of seconds you think the maximum time the query could take.
Further information on how to deal with Mysql connection issues.
EDIT: Two other settings you may want to also use is
net_write_timeout
andnet_read_timeout
.In my case it was low value of
open_files_limit
variable, which blocked the access of mysqld to data files.I checked it with :
After I changed the variable to big value, our server was alive again :
For Vagrant Box, make sure you allocate enough memory to the box
I used following command in MySQL command-line to restore a MySQL database which size more than 7GB, and it works.