A communication packet is a single SQL statement sent to a MySQL server, or a single line sent to the client.
The maximum possible packet of information between the MySQL 5.1 server and the client is 1GB.
When a MySQL client or mysqld server receives a packet larger than max_allowed_packet byte, it emits a "packet too large" error and closes the connection. For some clients, if the communication packet is too large, a "lost connection to the MySQL server" error can be encountered during query execution.
Both the client and the server have their own max_allowed_packet variables, so if you plan to handle large packets, you must increase the variables on both the client and the server.
If you are using the MySQL client program, the default value for the Max_allowed_packet variable is 16MB. To set a larger value, you can start MySQL in the following ways:
mysql> mysql --max_allowed_packet=32M
It sets the packet size to 32MB.
The default Max_allowed_packet value for the server is 1MB. If the server needs to process large queries, you can increase the value (for example, if you are preparing to handle large BLOB columns). For example, to set this to 16MB, you can start the server in the following ways:
mysql> mysqld --max_allowed_packet=16M
You can also use the option file to set the Max_allowed_packet. To set this variable to 16MB for the server, you can add the following line to the options file:
[mysqld]
max_allowed_packet=16M
Increasing the value of this variable is safe because additional memory is allocated only when needed. For example, mysqld allocates more memory only if you issue a long query or mysqld must return a large result row. The variable's smaller default value is a precaution to capture the error packets between the client and the server, and to ensure that there is no memory overflow caused by accidental use of large packets.
If you are using a large BLOB value and do not grant mysqld access to enough memory to process the query, you may also experience strange problems with large packets. If this situation is suspected, try adding ulimit-d 256000 to the Mysqld_safe script and restart mysqld.