MySQL error 2006: mysql server has gone away

2018-12-31 09:28发布

I'm running a server at my office to process some files and report the results to a remote MySQL server.

The files processing takes some time and the process dies halfway through with the following error:

2006, MySQL server has gone away

I've heard about the MySQL setting, wait_timeout, but do I need to change that on the server at my office or the remote MySQL server?

23条回答
泛滥B
2楼-- · 2018-12-31 10:19

It may be easier to check if the connection and re-establish it if needed.

See PHP:mysqli_ping for info on that.

查看更多
像晚风撩人
3楼-- · 2018-12-31 10:19

If you are using the 64Bit WAMPSERVER, please search for multiple occurrences of max_allowed_packet because WAMP uses the value set under [wampmysqld64] and not the value set under [mysqldump], which for me was the issue, I was updating the wrong one. Set this to something like max_allowed_packet = 64M.

Hopefully this helps other Wampserver-users out there.

查看更多
长期被迫恋爱
4楼-- · 2018-12-31 10:21

For users using XAMPP, there are 2 max_allowed_packet parameters in C:\xampp\mysql\bin\my.ini.

查看更多
永恒的永恒
5楼-- · 2018-12-31 10:23

In MAMP (non-pro version) I added

--max_allowed_packet=268435456

to ...\MAMP\bin\startMysql.sh

Credits and more details here

查看更多
无色无味的生活
6楼-- · 2018-12-31 10:23

This error is occur due to expire of wait_timeout .

Just go to mysql server check its wait_timeout :

mysql> SHOW VARIABLES LIKE 'wait_timeout'

mysql> set global wait_timeout = 600 # 10 minute or maximum wait time out you need

http://sggoyal.blogspot.in/2015/01/2006-mysql-server-has-gone-away.html

查看更多
栀子花@的思念
7楼-- · 2018-12-31 10:23

On windows those guys using xampp should use this path xampp/mysql/bin/my.ini and change max_allowed_packet(under section[mysqld])to your choice size. e.g

max_allowed_packet=8M

Again on php.ini(xampp/php/php.ini) change upload_max_filesize the choice size. e.g

upload_max_filesize=8M

Gave me a headache for sometime till i discovered this. Hope it helps.

查看更多
登录 后发表回答