Linux. Fixing ERROR 2006: MySQL server has gone away

This Linux snippet shows how to fix a ERROR 2006 thrown by a MySQL server.

This error usually occurs when the communication packet send to a MySQL server is too large. The communication packet can be either a single SQL statement, single row sent back to the client, or a binary log event set from master replication server to a slave. For example, the largest possible packet that can be transmitted to or from MySQL 5.5 server is 1GB. When the maximum allowed packet is exceeded the MySQL server closes the issues a Packet too large error (ERROR #2006) and closes the connection. It can also happen during a query to the MySQL server, if the communication packet is too big

To raise the default communication package limit, the following directives have to be added to the MySQL configuration file. For Fedora Linux the file is at /etc/my.cnf.

[mysqld]
max_allowed_packet= 64M
wait_timeout= 6000

Restart the MySQL server.

/etc/init.d/mysqld stop
/etc/init.d/mysqld start