Linux – Keep getting “MySQL has gone away” and “Error while sending QUERY packet”

centoslinuxMySQLWordpress

Explanation

There is a single wordpress website on a XEN VPS with CentOS (2GB RAM, 2 cores) with average visitors which was previously working on a cheap shared hosting without this kind of issues (transferred for other reasons).

  • 132 tables in database
  • Total database size 40MB
  • Largest table is 22MB, 5000 rows
  • Mostly (96%) select queries, average is 200k select queries per hour.

MySQL Network traffic:

----------------------------------
|    Traffic     |     per hour  |
----------------------------------
|   Received     |    64.6 MiB   |
|    Sent        |     1.5 GiB   |
|    Total       |     1.5 GiB   |
----------------------------------

free -m result:

             total       used       free     shared    buffers     cached
Mem:          1868       1636        232          4         32       1113
-/+ buffers/cache:        490       1378 
Swap:         1023         57        966

Issue

Keep getting two errors every 4-5 hours like this:

  1. Lots (20-40) of this error: Error while sending QUERY packet. PID=XXXX in ...wp-db.php on line 1942

  2. Some (3-5) of this error: mysqli_query(): MySQL server has gone away in ...

This happens for a few seconds or mostly 5 min, and then no errors at all for another 4-5 hours.


What I've done

As I understood this is related to max_allowed_packet , so I tried values from 256M to 900M without any success, also modified some other configs but reverted back after.

Current my.cnf file is as below (it was empty when the issue started happening):

[mysqld]
max_allowed_packet=524288000
open_files_limit=15000
wait_timeout=70
connect_timeout=70

Any suggestions or help is really appreciated.

Best Answer

You can also try increasing innodb_buffer_pool_size per this thread. That has helped me out in the past.

Related Topic