“Lost connection to MySQL server during query” error

Posted on

Question :

I have MySQL 5.5.20 and this table:

mysql> desc country;
+----------------+-------------+------+-----+---------+-------+
| Field          | Type        | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| id             | int(255)    | NO   | PRI | NULL    |       |
| iso            | varchar(2)  | NO   |     | NULL    |       |
| name           | varchar(80) | NO   |     | NULL    |       |
| printable_name | varchar(80) | NO   |     | NULL    |       |
| iso3           | varchar(3)  | YES  |     | NULL    |       |
| numcode        | smallint(6) | YES  |     | NULL    |       |
+----------------+-------------+------+-----+---------+-------+

If I run a query like this

SELECT country.ID, country.ISO, country.NAME,
       country.PRINTABLE_NAME, country.ISO3, country.NUMCODE
FROM country;

It returns:

ERROR 2013 (HY000): Lost connection to MySQL server during query

If I change the order of the columns (ISO3 before PRINTABLE_NAME for example) like this:

SELECT country.ID, country.ISO, country.NAME,
       country.PRINTABLE_NAME,  country.NUMCODE, country.ISO3
FROM country;

It works fine!

Or if I rewrite the query using lower-case letters for columns, it works as well.

This issue appears from time to time (about once a month) and the only solution to fix it is to restart MySQL!
i have checked error log and nothing added to error log upon this error!!
I am really confused and don’t know why this happens! Any ideas on how this could be fixed?

Answer :

I am running MySQL 5.7.26 on Windows and when doing just a simple query from the MySQL command line client I get that same error you describing. I found out it only occurs when the query length is exact 64 characters! Just by adding a space fixed the problem for me.
It doesn’t matter if it’s a select or insert/delete/update query.
I have run 66.000 queries on my server and only the queries with exact 64 characters failed.
I checked the database for corruption. But I could also reproduce same problem when making a new database and table on that server.
I could only reproduce this problem on that production server. I created a new server with same version with exact same settings as a VMWare machine but could not recreate. Used the same MySQL client.

Leave a Reply

Your email address will not be published.