MySQL error 2006: mysql server has gone away
I have encountered this a number of times and I've normally found the answer to be a very low default setting of max_allowed_packet
.
Raising it in /etc/my.cnf
(under [mysqld]
) to 8 or 16M usually fixes it. (The default in MySql 5.7 is 4194304
, which is 4MB.)
[mysqld]
max_allowed_packet=16M
Note: Just create the line if it does not exist
Note: This can be set on your server as it's running.
Note: On Windows you may need to save your my.ini or my.cnf file with ANSI not UTF-8 encoding.
Use set global max_allowed_packet=104857600
. This sets it to 100MB.
It may be easier to check if the connection exists and re-establish it if needed.
See PHP:mysqli_ping for info on that.
I had the same problem but changeing max_allowed_packet
in the my.ini/my.cnf
file under [mysqld]
made the trick.
add a line
max_allowed_packet=500M
now restart the MySQL service
once you are done.
I used following command in MySQL command-line to restore a MySQL database which size more than 7GB, and it works.
set global max_allowed_packet=268435456;