A MySQL error commonly encountered is to have “packet too large” reported and it is often coupled with a “lost connection to MySQL server during query” error as the server closes the connection. The errors occur when a MySQL communication packet exceeds the value set by the variable max_allowed_packet. Queries are meant to be sent and processed in one chunk, called a “packet,” which is stored in a temporary buffer. The limitation set for the packet, defined by max_allowed_packet, exists to prevent the server from running out of memory.

It is possible to increase the value of max_allowed_packet by explicitly setting the value in the configuration file. The default value for this variable is 4MB (1MB prior to MySQL 5.6.6). The maximum possible packet limit for this variable is 1GB.

Large blob fields may also play a role in these errors. It is recommended that max_allowed_packet be increased to a value as big as the largest blob used.

Wrap it up: A “packet too large” MySQL error is indicative of a query attempting to send bytes exceeding that set for a communication packet. Increase the max_allowed_packet variable especially if blobs or long strings are used in the MySQL database.

Share This