Fix Lost Connection Error on MySQL

Table of Contents

Lost Connection Error

One of the more common errors you’ll encounter while running a lengthy or tricky query on MySQL and is often experienced while mysqldump is up and running on a pretty extensive database is:

Error 2013: Lost connection to MySQL server during query

This error can be easily fixed by just simply updating the default MySQL query timeout limits

Display MySQL Timeout Variables

First, you must check their current values before changing these variables by just simply running:

SHOW SESSION VARIABLES LIKE 'wait_timeout';
SHOW SESSION VARIABLES LIKE 'interactive_timeout';


wait_timeout: is basically the number of seconds the server waits for activity on a noninteractive connection before closing it, while interactive_timeout: The number of seconds the server remains for activity on an interactive connection before closing it.

SET @@GLOBAL.wait_timeout=28800;
SET @@GLOBAL.interactive_timeout=28800

And the default value is always 28800 seconds (8 Hours)

Update MySQL Timeout

Now if the queries you’re working on require a little bit more time, you can change the values and you must change their value in seconds, for example, you need 24 hours for your query:

SET @@GLOBAL.wait_timeout=86400;
SET @@GLOBAL.interactive_timeout=86400

And just like that, You’ve updated your MySQL timeout easily. And if you want to make managing your data hassle-free and easy, Ottomatik can help you with automated backups to help you manage your databases efficiently and stress-free! Try Ottomatik free for 14 days and see a world of difference when backing up your servers.

Ready to secure your backups today?

Try for free
14 Day Free Trial • Cancel Anytime • No Credit Card Required