How to fix MySQL lost connection

SimpleBackups founder

Laurent Lemaire

Co-founder, SimpleBackups

September 13th, 2022

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.

Display MySQL timeout variables

Before updating the timeouts, let's check their current values.

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.

Update MySQL timeout

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.

Back to blog

Stop worrying about your backups.
Focus on building amazing things!

Free 7-day trial. No credit card required.

Not convinced yet? Need help?
Get in touch via chat or at [email protected]

Customer support with experts
Security & privacy first
Service that you'll love using