您的位置:首页 > 产品设计 > UI/UE

mysql5中大数据错误:Packet for query is too large (1117260 > 1048576). You can change this value on the ser

2016-04-05 17:35 801 查看
mysql5数据,插入或更新字段有大数据时(大于1M),会出现如下错误:

SEVERE: Servlet.service() for servlet [webs] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: Hibernate flushing: Could not
execute JDBC batch update; SQL [update t_article set (省略部分...)author_id=? where id=?];
Packet for query is too large (1117260 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.; nested exception is java.sql.BatchUpdateException: Packet for query
is too large (1117260 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.] with root cause java.sql.BatchUpdateException: Packet for query is too large (1117260 > 1048576). You can change this value on the server
by setting the max_allowed_packet' variable.

开始以为是相应字段的类型设置不正确,超出了字段的最大范围,网上查询后发现是mysql默认加载的数据文件不超过1M,可以通过更改mysql的配置文件my.cnf(Linux,或windows的my.ini)来更改这一默认值,从而达到插入大数据的目的。

解决:
MySQL的一个系统参数:max_allowed_packet,其默认值为1048576(1M),
可以先查询一下:show VARIABLES like '%max_allowed_packet%';
修改此变量的值:MySQL安装目录下的my.ini文件中的[mysqld]段中的"max_allowed_packet = 1M",如更改为4M(如果没有这行内容,增加一行),保存,重新启动MySQL服务。现在可以load大于1M的文件了。

有时候命令“SET GLOBAL max_allowed_packet=16*1024*1024”无效,需要使用如下命令:set @@max_allowed_packet=5*1024*1024
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息