伴职创作「banzhi.cc」书客创作[ibooker.cc]程序员

【数据库】MySQL5更新大数据错误

2017-11-25  本文已影响78人  吾非言

作者:邹峰立,微博:zrunker,邮箱:zrunker@yahoo.com,微信公众号:书客创作,个人平台:www.ibooker.cc

本文选自书客创作平台第145篇文章。阅读原文

书客创作

当MySQL进行数据插入或者更新的时候,可能会报出以下错误:

### Error updating database.  Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1591442 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: UPDATE IGNORE t_article    SET a_title=?,             a_abstract=?,             a_atid=?,             a_atsid=?,             a_content=?,             a_html=?,                 a_cover_path=?,             a_ispub=?,             a_isallow=?,             a_isdelete=?    WHERE a_id=? AND a_uid=?
### Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1591442 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
; SQL []; Packet for query is too large (1591442 > 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 (1591442 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.

由以上错误内容可以看出,当出入数据大于1M的时候会抛出PacketTooBigException异常。
这是由于MySQL5更新数据最大允许默认值为1048576(1M)。

解决办法:

1、可以进行通过配置文件my.ini进行设置。
在MySQL安装目录下找到my.ini文件,打开文件找到[mysqld]段中的找到max_allowed_packet = 1M,增大max_allowed_packet的值即可。之后保存,重启MySQL服务。
注意:有的版本可能没有max_allowed_packet,可以自行在[mysqld]段中添加。

2、可以使用命令“SET GLOBAL max_allowed_packet=810241024”或:set @@max_allowed_packet=8 *1024 *1024。

阅读原文


微信公众号:书客创作
上一篇 下一篇

猜你喜欢

热点阅读