Thursday, December 25, 2014

MySQL server - Lost connection to server during query

There are many reasons for such an error, thats why MySQL wrote a dedicated subsection at their reference manual (
It happened to me just yesterday while trying to query a large table. 
The way I debugged it was by setting the following: 
1. Log level to 2:  --log-warnings=2 
2. Turn on the slow queries log: slow-query-log=1
Running the query again, revealed the following error in MySQL log file: 
"...Got timeout writing communication packets"

Make sure that your timeout parameters were not set in your MySQL configuration file - their default is: 480 hours which is enough:
Set the following parameters to 28800 seconds - the default is: 60 seconds which is very low for such a query: