. Advertisement .
..3..
. Advertisement .
..4..
Having trouble dealing with the error code: 2013. Lost connection to MySQL server during query?
Struggling no more with our help on your back! Read on for further helpful details.
What Causes The Lost Connection To Mysql Server During Query Error?
As tricky as other MySQL bugs, this error message might be the consequence of three possible factors.
Network Connectivity Issues
If this problem happens repeatedly, it usually implies network connectivity issues. This is most likely the case considering the error message contains the phrase “during query.” Then the solution is simply for you to verify the state of your network.
The Reading Time Is Not Enough
Change The Timeout Global Variables In The MySQL Database Server
When millions of rows are transmitted as part of one or more queries, there is a chance the “during query” form might appear.
If you’re aware that this is happening, consider raising net_read_timeout from the 30-second default to 60 seconds or greater, which should be enough time for the data transmission to finish.
You can raise the timer to 60 seconds using the command as follows:
mysql -uroot -proot –connect-timeout 60
The number 60 is adjustable for you to modify into whatever amount of seconds you want to wish. Once done with that, remember to try executing your query again to check whether everything gets the job successfully.
There is only one minor heed is that the –connect-timeout alternative varies the timeout seconds for a short period of time. It only works for the current MySQL session, so you’ll have to utilize this function every time you want to extend the connection timeout.
Change The Timeout Global Variables In The MySQL Configuration Files
You may also alter the my.cnf (Mac) or my.ini (Windows) file used by your MySQL connection if you’re using a MySQL configuration file to control the parameters of your connections.
In such a case, open that configuration file in your preferred text editor and look for the variables below in MySQL:
[mysqld]
connect_timeout = 10
net_read_timeout = 30
wait_timeout = 28800
interactive_timeout = 28800
The interactive_timeout and wait_timeout variables should be unaffected since their default values are 28800 seconds (8 hours), which is already vastly decent in employment.
All you need to do is merely advance the net_read_timeout and connect_timeout variable settings; and that’s how you can to avoid the timeout error. As such, I’d recommend a timer of at least 600 seconds, or 10 minutes.
Change The Timeout Global Variables In The MySQL GUI Tools
If you are employing a GUI MySQL tool such as MySQL Sequel Ace, Workbench, or PHPMyAdmin, you may locate timeout-related variables in the preferences or settings menu of these programs.
- In MySQL Workbench for Windows, for example, timeout-related options may be found in Edit > Preferences > SQL Editor.
- As for Mac, you will locate you need in MySQLWorkbench > Preferences > SQL Editor
The Bottom Line
Hopefully, this tutorial regarding how to fix lost connection to MySQL server during query error can be of great use to you somehow. Don’t forget to stay tuned for our next updates, see you then!
Leave a comment