One day I suddenly got the ”MySQL server has gone away” error message in my web-application. No queries were running. The webpage (cron update) that generates the error is a heavy one with approx. 10 000 queries. I had never seen this error message before and the solutions to fix it seems to be different in each case. The way I solved the error was the following.
1) I ran ”mysqlcheck” in repair mode and it fixed problems with clients that were using or hadn’t closed tables properly.
2) I found this workaround.
3) Then I checked the mysql servers system variable wait_timeout with:
mysqladmin -u username -p variables
The value was 10 which were pretty low considering the default value which is 28800.
wait_timeout is the number of seconds the server waits for activity on a noninteractive connection before closing it. This timeout applies only to TCP/IP and Unix socket file connections, not to connections made using named pipes, or shared memory.
4) I searched and found the ”wait_timeout” value in the mysql config file /etc/my.cnf. I had set this value to 10 when I did some mysql performance optimization in the past. Then I raised this value to a higher number.
5) Restarted mysql and ran the webpage. Everything worked fine.
I still don’t know why this error occured that day. The server configuration worked good before the accident and I haven’t made any changes lately. Very strange!