小编给大家分享一下Mysql中max_allowed_packet设定的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
十余年建站经验, 网站设计制作、成都网站设计客户的见证与正确选择。创新互联建站提供完善的营销型网页建站明细报价表。后期开发更加便捷高效,我们致力于追求更美、更快、更规范。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.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
修改后
[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
重启容器并确认
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" |bc 268435456 liumiaocn:~ liumiao$
看完了这篇文章,相信你对“Mysql中max_allowed_packet设定的示例分析”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!