- 目的:mysql根据配置文件会限制server接受的数据包大小。有时候大的插入和更新会被max_allowed_packet 参数限制掉,导致失败。
- 环境:ubuntu14.04
定义:
max_allowed_packet:server接受的数据包最大值
查看方法:
mysql> show VARIABLES like '%max_allowed_packet%';
显示结果:
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
以上说明目前的配置是:1M
修改方法:
- 编辑mysql.cnf中的[mysqld]段,增加/修改为:max_allowed_packet = 20M
- 然后,重启mysql服务,再次进行查看以确认是否设置生效。
p.s.这样的修改方式不会因为重启服务而丢弃设置。
注意:
1.如果找不到mysql.cnf文件,可以在/etc/目录下查找“mysql*.cnf":
linda@linda-pc:/etc$ find -name "mysql*.cnf"
find: `./docker': Permission denied
find: `./ssl/private': Permission denied
find: `./cups/ssl': Permission denied
find: `./polkit-1/localauthority': Permission denied
find: `./dovecot/private': Permission denied
./mysql/mysql.cnf
./mysql/conf.d/mysql.cnf
./mysql/mysql.conf.d/mysqld.cnf
2.
重启mysql服务:
linda@linda-pc:/etc/init.d$ sudo service mysql restart
* Stopping MySQL Community Server 5.7.18
.....
* MySQL Community Server 5.7.18 is stopped
* Re-starting MySQL Community Server 5.7.18
..
* MySQL Community Server 5.7.18 is started