max_allowed_packet是Mysql中的一个设定参数,用于设定所接受的包的大小,根据情形不同,其缺省值可能是1M或者4M,比如是4M的情况下,这个值的大小即为:4 *1024*1024= 4194304
现象
当日志中出现了诸如:“Package for query is too large (xxxxxxxx > 4194304). You can change this value on the server by setting the max_allowed_package variable”的提示的时候,错误的本身就清楚的提示了对应的方式。
确认max_allowed_package
使用如下的方式可以确认当前设定值
mysql> select @@max_allowed_packet;+----------------------+| @@max_allowed_packet |+----------------------+| 4194304 |+----------------------+1 row in set (0.00 sec)mysql>
或者
mysql> show variables like 'max_allowed_packet';+--------------------+---------+| Variable_name | Value |+--------------------+---------+| max_allowed_packet | 4194304 |+--------------------+---------+1 row in set (0.00 sec)mysql>
修改
可以使用set命令来修改,但是只是临时修改,重启后即丢失。也可以直接修改过 mysql的设定文件并重启mysql服务,即可永久化保证设定。
根据mysql的安装不同修改的文件也会有所不同,普通安装方式可能会修改my.cnf,这里使用mysql的官方镜像,其修改的文件应该为:/etc/mysql/mysql.conf.d/mysqld.cnf
修改内容:向此文件中添加如下设定
max_allowed_packet = 256M
修改前
[mysqld]pid-file = /var/run/mysqld/mysqld.pidsocket = /var/run/mysqld/mysqld.sockdatadir = /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 riskssymbolic-links=0
修改后
[mysqld]pid-file = /var/run/mysqld/mysqld.pidsocket = /var/run/mysqld/mysqld.sockdatadir = /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 riskssymbolic-links=0max_allowed_packet = 256M
重启容器并确认
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>
所以已经看到已经成功设定为256M(268435456)了
liumiaocn:~ liumiao$ echo "256*1024*1024" |bc268435456liumiaocn:~ liumiao$
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对VeVb武林网的支持。
注:相关教程知识阅读请移步到MYSQL教程频道。