If you are working with MySQL long enough, you might run into this error:


error 2013 (hy000): lost connection to mysql server during query


Or 


error 2013 (hy000): lost connection to mysql server at 'handshake: reading initial communication packet'


That means it took too long for the query to return data, the server timed out and closed the connection. The client didn’t get an error when writing to the server, but it didn’t get a full answer (or any answer) to the question.


Here are some quick fixes:


1. Modify the server variables settings


You can go to the server’s setting and increase the value of net_read_timeout or connect_timeout values that it’s sufficient for the data transfer to complete. 

For the large tables, you may be experiencing a problem with BLOB values that are larger than max_allowed_packet, then you need to increase the max_allowed_packet value.


2. Client’s timeout values


If you are using TablePlus and it returns “Lost connection to server during query” error when running long query, please try:

  • Go to the preferences setting (Cmd + ,)
  • From the General panel, increase the Query timeout value

TablePlus Query Timeout

3. Refine the queries

You can also rewrite your MySQL query and avoid making a long query, overly complex query with many joins, group by, or aggregate functions. It will not only avoid getting timed out but also improve query performance.


Need a good MySQL GUI? TablePlus provides a native client that allows you to access and manage MySQL and many other databases simultaneously using an intuitive and powerful graphical interface.

Download TablePlus for Mac.

Not on Mac? Download TablePlus for Windows.

Need a quick edit on the go? Download for iOS

TablePlus in Dark mode