How to fix lost connection to MySQL server during query?

Alton Alexander
By Alton AlexanderUpdated on June 4th, 2022

This error code happens when the MySQL server loses connection to the query. This can happen for a variety of reasons, including but not limited to: the server being down, the network being down, or the query taking too long to execute.

People like you are also looking for:

  • mysql error code 2013
  • lost connection to mysql server during query

1. Check if the server is running

  1. Check if the MySQL server is running mysql -u root -p
  2. Check the status of the MySQL server mysql -V
  3. Check the log files to see if there are any errors mysql -u root -p < /var/log/mysql/error.log
  4. Check the status of the mysqld daemon service mysqld status
  5. Check the status of the mysqld processes ps -ef | grep mysqld
  6. If necessary, restart the MySQL server or mysqld daemon

2. Check if the server is accessible

  1. Open a command prompt and change directory to the MySQL installation directory.
  2. Issue the following command to test your server's connectivity to the MySQL server. mysql -uroot -p
  3. If the server is accessible, you will see the following response. mysql> SHOW VERSION; mysql Ver 5.6.25-0ubuntu0.14.04.1-log

3. Check if the connection is configured properly

  1. Verify that the MySQL server is running and accessible.
  2. Check the server's configuration to ensure that the proper MySQL connection parameters are in place.
  3. Verify that the MySQL client software is installed and configured correctly.
  4. If the connection fails, check the network connection and the MySQL server configuration.

If the answers above didn't work then you should also try:

  1. Check if the query is valid
  2. Check if the table exists
  3. Check if the user has permission to access the table
  4. Check if the user has permission to execute the query