mysql max_allowed_packet 设置

mysql根据my.cnf中max_allowed_packet的大小来限制接收到的数据包大小。

官网描述,如下图。 数据包的值范围为1k~1G, 只能是1024的倍数,不能整除1024的,会向下取整。 若设置成1025,最终结果为1024。

 

查看方法:

1.在mysql配置文件中my.cnf中查看。cat my.cnf

my.cnf可通过 mysql --help|grep my.cnf查找,一般在/etc/mysql下。

2.登陆mysql(mysql -h ip -u userName -ppasswd databaseName -A ),通过命令行查看。show variables like "max_allowed_packet";

 此时显示大小为16M

 

修改方法:

1.直接在my.cnf中修改。

2.在命令行中用 set global max_allowed_packet = 1;设置。 

max_allowed_packet最小值为1024, 如设置的值<1024, 则默认为1024。

执行成功后,退出登陆,再重新登录。用show variables like "max_allowed_packet"查看即可发现修改成功。

此时大小显示为1kb

 

若数据包大小> max_allowed_packet,则会有错误信息:

ERROR 1153 (08S01): Got a packet bigger than 'max_allowed_packet' bytes

测试用例:

 将max_allowed_packet设置为1024即1kb

建表语句:

CREATE TABLE `max_allowed_test` (
  `msg` varchar(256) NOT NULL DEFAULT '',
  `info` varchar(1024) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8 

插入语句:

insert into max_allowed_test values("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy");

数据包的大小,是指什么呢? sql语句的长度,还是插入数据的大小。下面来验证一下。

插入的数量大小刚好是1025,即xxx+yyy的字符个数=1025;

结果:

成功了。

 

原因:

数据包其实是网络包缓冲区的大小。包会进行层层封装,并且还会进行压缩,并不是单纯的只sql语句或者插入语句的大小,详情参考:http://blog.itpub.net/7728585/viewspace-2138631/

 

转载于:https://www.cnblogs.com/happySmily/p/8066414.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值