问题
I'm having an issue with a PHP7 script saving data to a database (MariaDB). The script worked fine on a previous hosting package, but not on my new VPS.
Warning: Error while sending QUERY packet. PID=1208 in ...
Other threads caused me to look at settings, but my settings are:
- max_allowed_packet = 1GB
- wait_timeout = 10
I've reviewed the issue further and found there is nothing wrong with the query itself (it executes fine in phpMyAdmin).
It seems to be something to do with executing two queries in close succession without closing the connection (the second one fails).
The same script ran fine on the old hosting, it must be a setting - does anyone have any ideas?
Many thanks, Ben
MariaDB config (/etc/my.cnf):
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1GB
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
innodb_file_per_table
max_connections=70
max_user_connections=30
wait_timeout=10
interactive_timeout=50
long_query_time=5
回答1:
1 minute after asking it, I've answered my own question. This was the issue:
wait_timeout=10
My previous hosting configuration had =180 which make my poorly written script work. Under the =10 it's just not long enough for the task to complete. I have lengthened it to 180 now but should really add handle for this.
回答2:
I have this same issue and it's super annoying. The queries are running fast, but at some point they keep hanging and locks up for no reason explainable. I have it on 60 seconds and don't think increasing it is a good solution.
Does this mean that the script takes over 60 seconds and the database is gone?
However I have noticed the SQL's are "deadlocking", because they hang in SHOW PROCESSLIST. I only use SELECT + JOIN. So the SQL are the issue... but when I run them they are quick... it's so weeeird.
You said it's the connection not being closed, but that makes no sense. Connection is closed automatically.
来源:https://stackoverflow.com/questions/41398490/mariadb-error-while-sending-query-packet-not-max-allowed-packet