Tuesday, March 15, 2011

How to fix “MySQL server has gone away” (error 2006)

Two most common reasons (and fixes) for the MySQL server has gone away (error 2006) are:
1. Server timed out and closed the connection. How to fix: check that wait_timeout variable in your mysqld’s my.cnf configuration file is large enough. Set wait_timeout = 600 seconds (you can tweak/decrease this value when error 2006 is gone), then restart the mysql.
2. Server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection. You can increase the maximal packet size limit by increasing the value of max_allowed_packet in my.cnf file. Set max_allowed_packet = 64M (you can tweak/decrease this value when error 2006 is gone), then restart the mysql.