向mysql插入过大数据时,会报这个错。一般是某一字段过长
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (3413886 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
; SQL []; Packet for query is too large (3413886 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.; nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (3413886 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.</faultstring>
完整的报错信息就是这个,可以看出是字段过长,要更改数据库参数
修改方法
1) 方法1
可以编辑my.cnf来修改(windows下my.ini),在[mysqld]段或者mysql的server配置段进行修改。
max_allowed_packet = 20M
如果找不到my.cnf可以通过
mysql --help | grep my.cnf
去寻找my.cnf文件。
2) 方法2
进入mysql server
在mysql 命令行中运行
set global max_allowed_packet = 2*1024*1024*10
然后关闭掉这此mysql server链接,再进入。
show VARIABLES like '%max_allowed_packet%';
查看下max_allowed_packet是否编辑成功