Max allowed packet setting of Mysql

Posted by gabrielkolbe on Mon, 30 Dec 2019 16:42:23 +0100


max_allowed_packet is a setting parameter in Mysql, which is used to set the size of the accepted package. According to different situations, the default value may be 1M or 4M. For example, in the case of 4M, the size of this value is: 4 * 1024 * 1024 = 4194304

phenomenon

When a prompt appears in the log, such as "Package for query is too large (XXXXXXX > 4194304). You can change this value on the server by setting the max? Allowed? Package variable", the error itself clearly indicates the corresponding way.

Confirm max? Allowed? Package

Use the following method to confirm the current setting value

mysql> select @@max_allowed_packet;
+----------------------+
| @@max_allowed_packet |
+----------------------+
|              4194304 |
+----------------------+
1 row in set (0.00 sec)

mysql>

perhaps

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

mysql>

modify

You can use the set command to modify it, but only temporarily. It will be lost after restart. You can also modify the mysql settings file directly and restart the mysql service to ensure the settings are permanent.
According to the installation of MySQL, the modified files will be different. The normal installation mode may modify my.cnf. Here, the official image of MySQL is used. The modified file should be / etc/mysql/mysql.conf.d/mysqld.cnf

Modification: add the following settings to this file
max_allowed_packet = 256M

Before modification

[mysqld]
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
datadir		= /var/lib/mysql
#log-error	= /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address	= 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

After modification

[mysqld]
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
datadir		= /var/lib/mysql
#log-error	= /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address	= 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_allowed_packet = 256M

Restart container and confirm

mysql> show variables like '%max_allowed_pack%';
+--------------------------+------------+
| Variable_name            | Value      |
+--------------------------+------------+
| max_allowed_packet       | 268435456  |
| slave_max_allowed_packet | 1073741824 |
+--------------------------+------------+
2 rows in set (0.01 sec)

mysql>

So we have seen that it has been set to 256M(268435456) successfully

liumiaocn:~ liumiao$ echo "256*1024*1024" |bc
268435456
liumiaocn:~ liumiao$

Topics: MySQL socket