Change mysql max_allowed_packet variable

There are several ways to change the max_allowed_packet variable size in mysql


1. Edit max_allowed_packet entry of /etc/my.cnf file (on Linux). Change the following line

[mysqld]
max_allowed_packet=16M

2. Start the mysql server with the --max_allowed_packet option.

/etc/init.d/mysql restart --max_allowed_packet=1024M

3. To edit the max_allowed_packet without restarting the server.

mysql> show variables like 'max_allowed_packet%' ;
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
1 row in set (0.00 sec)

mysql> set max_allowed_packet = 1073741824;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like 'max_allowed_packet%' ;
+-----------------------------------+---------------------+
| Variable_name | Value |
+----------------------------------+---------------------+
| max_allowed_packet | 1073741824 |
+--------------------+------------+----------------------+