mysql报错Packet for query is too large问题解决

今天用java写了批量插入运行时,报错:

Packet for query is too large (1128576 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.

出现问题的原因:批量插入数据量过大

MySQL根据配置文件会限制Server接受的数据包大小。有时候插入、更新或查询时数据包的大小,会受 max_allowed_packet 参数限制,导致操作失败。

mysql> show VARIABLES like '%max_allowed_packet%';
+--------------------------+------------+
| Variable_name | Value |
+--------------------------+------------+
| max_allowed_packet | 1048576 |
| slave_max_allowed_packet | 1073741824 |
+--------------------------+------------+

说明:

  1*1024*1024 = 1048576 =1M

解决办法

修改mysql配置文件 windows下 my.ini

在[mysqld]下添加

max_allowed_packet = 524288000

说明:

  500*1024*1024 =524288000=500M

修改完成之后要重启mysql

mysql> show VARIABLES like '%max_allowed_packet%';
+--------------------------+------------+
| Variable_name | Value |
+--------------------------+------------+
| max_allowed_packet | 524288000 |
| slave_max_allowed_packet | 1073741824 |
+--------------------------+------------+

  

上一篇:Mysql 改变packet大小及导入sql,sql文件过大,导入导出缓慢解决办法


下一篇:--whole-archive 和 --no-whole-archive的区别