When running a long or complex query on MySQL you might encounter the error below:
Error 2013: Lost connection to MySQL server during query
This error is often faced when running mysqldump on a large database.
In order to fix this error, you will have to update the default MySQL query timeout limits as explained below.
Before updating the timeouts, let's check their current values.
SHOW SESSION VARIABLES LIKE 'wait_timeout'; SHOW SESSION VARIABLES LIKE 'interactive_timeout';
wait_timeout : The number of seconds the server waits for activity on a noninteractive connection before closing it.
interactive_timeout: The number of seconds the server waits for activity on an interactive connection before closing it.
For each the default value is 28800 (seconds) so 8 hours.
If your queries require more time than the default values returned in the previous step, you can update them as follow:
SET @@GLOBAL.wait_timeout=57600; SET @@GLOBAL.interactive_timeout=57600
In this example, we've doubled the timout to 16 hours.