MySQL Got a packet bigger than 'max_allowed_packet', max_allowed_packet is automatically reset to 1024

MySQL reports an error when inserting or modifying data,  Got a packet bigger than 'max_allowed_packet', the solution to the solution that the packet size exceeds the value set by max_allowed_packet.

 

 

  1. Check the value of max_allowed_packet:
    root@VM-202-164-ubuntu:/home/ubuntu#mysql -u root -p
    Enter password:
    mysql> show VARIABLES like '%max_allowed_packet%';
    +--------------------------+------------+
    | Variable_name            | Value      |
    +--------------------------+------------+
    | max_allowed_packet       | 1024   |
    | slave_max_allowed_packet | 1073741824 |
    +--------------------------+------------+
    2 rows in set (0.07 sec)
     It can be seen that the value of max_allowed_packet is set to 1k, and an error will be reported if the packet size exceeds 1K.
  2. Modify the value of max_allowed_packet in the MySQL configuration file:
    root@VM-202-164-ubuntu:/home/ubuntu# cd /etc/mysql/mysql.conf.d
    root@VM-202-164-ubuntu:/etc/mysql/mysql.conf.d# vi mysqld.cnf
     Modify the value of max_allowed_packet under [mysqld]
    max_allowed_packet      = 20M
     Here is set to 20M
  3. Restart MySQL:
    root@VM-202-164-ubuntu:/home/ubuntu#/etc/init.d/mysql restart
     
  4. verify:
    root@VM-202-164-ubuntu:/home/ubuntu#mysql -u root -p
    Enter password:
    mysql> show VARIABLES like '%max_allowed_packet%';
    +--------------------------+------------+
    | Variable_name            | Value      |
    +--------------------------+------------+
    | max_allowed_packet       | 20971520   |
    | slave_max_allowed_packet | 1073741824 |
    +--------------------------+------------+
    2 rows in set (0.07 sec)
     It can be seen that the value of max_allowed_packet has become 20971520, which is 20M. Successfully solved!

It is also possible to directly modify the variable value without modifying the configuration file, but this is only a temporary method. After this setting, the value of max_allowed_packet will be restored to the value in the configuration file when mysql is restarted again. Methods as below:

 

root@VM-202-164-ubuntu:/home/ubuntu#mysql -u root -p
Enter password:
mysql> show VARIABLES like '%max_allowed_packet%';
+--------------------------+------------+
| Variable_name            | Value      |
+--------------------------+------------+
| max_allowed_packet       | 1024|
| slave_max_allowed_packet | 1073741824 |
+--------------------------+------------+
2 rows in set (0.07 sec)
mysql>set global max_allowed_packet = 2*1024*1024*10;

 

 

 The unit of the variable is b, so 2*1024*1024*10 is 20M;

Restart mysql, check the variable again, and find that it has successfully become 20971520 (please see above for the method of restarting mysql).

 

Solution for max_allowed_packet being reset automatically

After modifying the value of max_allowed_packet through the above method, the program runs normally, but after a day, it is found that this error starts to be reported again. Check the variable value of max_allowed_packet and find that it has become 1024, and the error is reported one day after the modification again..., but the configuration The value in the file is still 20M.

 

看了好多大神的博客,有些博客中说是因为mysql被远程恶意操作了。想想确实有这种可能,我的远程登录数据库的密码太简单了想要破解并不难,但我很奇怪,别人操作我的数据库,并改这个值有什么用呢?尝试了一下,修改了一个复杂数据库密码,几天后发现max_allowed_packet没有被重置过,成功解决了这个问题!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326035102&siteId=291194637