Bobcares

MySQL error 1160 – How to fix

by | Jul 6, 2021

Wondering how to fix MySQL Error 1160? We can help you!

Often our customers report to us that they get this error in their MySQL and connection to MySQL was lost.

Here at Bobcares, we often handle requests from our customers to fix similar errors as a part of our Server Management Service.

Today let’s see how our Support Engineers fix this issue for our customers.

How to fix MySQL Error 1160

Before going into the steps for fixing this error we will see what causes this error.

From the logs we will be able to see the following warning:

120611 16:12:30 [Warning] Aborted connection 2619503 to db: ‘db_name’ user: ‘user_name’ host: ‘webapp_hostname’ (Got an error reading communication packets)

This means that the connection to MySQL is actually aborted, and the site that uses the database will not be working most likely.

Generally, we see Joomla or other CMS-based websites affected by this issue.

Causes for this error:

Following are some of the causes for this error:

1. We may end up with this error if we send a query to the server that is incorrect or too large.

When mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection.

If we wish to use big queries (for example, if we are working with big BLOB columns), we can increase the query limit by changing the server’s max_allowed_packet. By default value of max_allowed_packet is 1MB.

Also, we may have to increase the maximum packet size on the client end. More information on setting the packet size is given in Section C.5.2.10, “Packet too large”.

2. An INSERT or REPLACE statement that inserts a great many rows can also cause these sorts of errors.

Either one of these statements sends a single request to the server irrespective of the number of rows to be inserted; thus, we can often avoid the error by reducing the number of rows sent per INSERT or REPLACE.

3.The most probable cause is MySQL’s query cache mechanism, so first, check if query cache is enabled:

mysql> show variables like '%query_cache%';
+------------------------------+---------+
| Variable_name | Value |
+------------------------------+---------+
| have_query_cache | YES |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 0 |
| query_cache_strip_comments | OFF |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
+------------------------------+---------+
7 rows in set (0.00 sec)

Note: The issue appears only if the nd_mysqli PHP extension enabled.

Steps to fix MySQL error 1160

We will see two methods with which we can fix this error.

Method 1:

1. We can try to increase the max_allowed_packet to a much larger number since the default is 1M.

2. This can be done about 10 times the largest TEXT or BLOB field we have in our current dataset.

3. For setting the max_allowed_packet to 256M, we can add it to /etc/my.cnf or my.ini

[mysqld]
max_allowed_packet=256M

3. Then save the file and exit.

4. After that we can run the following command:

SET GLOBAL max_allowed_packet = 1024 * 1024 * 256;

Method 2:

If we face the issue with Aborted connection messages (it applies to MySQL 5.7 only), we can try to disable query_cache first, or use mysqli PHP extension instead of nd_mysqli.

[Need assistance? We can help you]

Conclusion

To conclude, we saw the steps that our Support Techs follow to fix MySQL error 1160 for our customers.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.