mysql报错Packet for query is too large (12238 > 1024). You can change this value

  今天将项目部署到linux服务器的时候莫名其妙的报一些错误,可是在本地啥错没有,通过实时查看tomcat 的日志之后发现报错是:  

实时查看日志:

1、先切换到:cd usr/local/tomcat5/logs

2、tail -f catalina.out

3、这样运行时就可以实时查看运行日志了

发现错误:

rg.springframework.dao.TransientDataAccessResourceException:
### Error querying database.  Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1233 > 1024). You can change this value on the server by setting the max_allowed_packet‘ variable.
### The error may exist in cn/xm/exam/mapper/employee/out/custom/UnitCustomMapper.xml
### The error may involve cn.xm.exam.mapper.employee.out.custom.UnitCustomMapper.getHaulunitByCondition-Inline
### The error occurred while setting parameters
### SQL: SELECT   haulunit.unitId,   haulunit.unitBigId,   haulunit.bigId,   (select   group_concat(projectname) from project where projectid in (select projectId from   haulunitproject where bigId =haulunit.bigId and unitId=   haulunit.unitId)) as   projectNames,   haulunit.manager,   haulunit.managerPhone,   haulunit.secure,   haulunit.securePhone,   @b:=   (IFNULL((SELECT SUM(minusNum) FROM breakrules,   haulemployeeout WHERE   breakrules.BigEmployeeoutId =   haulemployeeout.BigEmployeeoutId    AND haulemployeeout.unitid =   haulunit.unitId           and breakTime LIKE CONCAT(Year(CurDate()),‘%‘)   ),0)) AS unitMinisMum,   haulinfo.bigName,   haulinfo.bigStatus,   haulinfo.bigCreateDate,   unit.name,   unit.address,   unit.contact,   unit.phone,   @a:= (SELECT   COUNT(BigEmployeeoutId)   FROM haulemployeeout   WHERE   haulemployeeout.bigId   = haulunit.bigId   AND haulemployeeout.unitId =   haulunit.unitId and trainstatus=‘2‘) AS   personNum,   TRUNCATE(IFNULL(@b/@a,0),3) AS jiaquan   FROM haulunit,   haulinfo,   unit    WHERE haulunit.bigId=haulinfo.bigId AND    haulunit.unitId=unit.unitId                      and haulunit.bigId = ?     ORDER BY jiaquan desc               limit ?,?
### Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1233 > 1024). You can change this value on the server by setting the max_allowed_packet‘ variable.
; SQL []; Packet for query is too large (1233 > 1024). 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 (1233 > 1024). You can change this value on the server by setting the max_allowed_packet‘ variable.
        at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:107)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)

-----------------解决办法:(通过查看mysql全局变量发现原因是mysql限制了最大更新大小)----------------------

mysql max_allowed_packet 设置过小导致记录写入失败

mysql根据配置文件会限制server接受的数据包大小。

有时候大的插入和更新会受max_allowed_packet 参数限制,导致写入或者更新失败。

查看目前配置

show VARIABLES like ‘%max_allowed_packet%‘;

显示的结果为:

+--------------------+---------+

| Variable_name      | Value   |

+--------------------+---------+

| max_allowed_packet | 1048576 |

+--------------------+---------+

以上说明目前的配置是:1M

修改方法

1、修改配置文件

可以编辑my.cnf来修改(windows下my.ini),在[mysqld]段或者mysql的server配置段进行修改。

max_allowed_packet = 20M

如果找不到my.cnf可以通过

mysql --help | grep my.cnf

去寻找my.cnf文件。

linux下该文件在/etc/下。

2、在mysql命令行中修改

在mysql 命令行中运行

set global max_allowed_packet = 2*1024*1024*10

然后退出命令行,重启mysql服务,再进入。

show VARIABLES like ‘%max_allowed_packet%‘;

查看下max_allowed_packet是否编辑成功

注意:该值设置过小将导致单个记录超过限制后写入数据库失败,且后续记录写入也将失败。

 

三、如何重启Linux的mysql

1、使用 service 启动:service mysqld restart

2、使用 mysqld 脚本启动:/etc/inint.d/mysqld restart

原文地址:https://www.cnblogs.com/qlqwjy/p/8366548.html

时间: 2024-10-14 07:43:15

mysql报错Packet for query is too large (12238 > 1024). You can change this value的相关文章

Packet for query is too large (12238 > 1024). You can change this value

原文 https://blog.csdn.net/java_mr_zheng/article/details/50469203 mysql max_allowed_packet 设置过小导致记录写入失败 mysql根据配置文件会限制server接受的数据包大小. 有时候大的插入和更新会受max_allowed_packet 参数限制,导致写入或者更新失败. 查看目前配置 show VARIABLES like '%max_allowed_packet%'; 显示的结果为: +----------

com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1169 > 1024)

### Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1169 > 1024). You can change this value on the server by setting the max_allowed_packet' variable. ; SQL []; Packet for query is too large (1169 > 1024). You can change

nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1044 > 1024

HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.hibernate.exception.GenericJDBCException: could not execute query org.hibernate.exce

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

原因是mysql 默认允许的 数据报包 是 1M  设置大一些就可以了 centos 下面  /ect/my.cnf 文件里面 加入或者修改 下面的参数 [mysqld] max_allowed_packet=20M 这个可以查询 允许的最大数据报包 SHOW VARIABLES LIKE '%max_allowed_packet%'; Packet for query is too large (1660 > 1024). You can change this value on the se

【Mysql操作容量限制问题】Error updating database. Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1082 > 1024)

在做查询数据库操作时,报了以上错误,还有out of memery heap hacp ,原因是mysql的max_allowed_packet设置过小引起的,我一开始设置的是1M,后来改为了20M mysql根据配置文件会限制server接受的数据包大小. 有时候大的插入和更新会被max_allowed_packet 参数限制掉,导致失败. 查看目前配置 show VARIABLES like '%max_allowed_packet%'; 显示的结果为: +-----------------

Packet for query is too large (1166 > 1024). You can change this value

转载: MySQL max_allowed_packet 设置过小导致记录写入失败 mysql根据配置文件会限制server接受的数据包大小. 有时候大的插入和更新会受max_allowed_packet 参数限制,导致写入或者更新失败. 查看目前配置 show VARIABLES like '%max_allowed_packet%'; 显示的结果为: 修改方法 1.修改配置文件 可以编辑my.cnf来修改(windows下my.ini),在[mysqld]段或者mysql的server配置段

Mysql数据中Packet for query is too large错误的解决方法

有时,程序在连接mysql执行操作数据库时,会出现如下类似错误信息: Packet for query is too large (4230 > 1024). You can change this value on the server by setting the max_allowed_packet' variable. 这个错误的大致原因是:向mysql数据库发送查询命令时,默认性况下,一个包的大小是1024,实际一条语句的长度,就大小这个,所以执行语句报错.解决的方式,就是调整mysq

mysql提示Packet for query is too large (1142 > 1024)解决方案

注:最近mysql一直提示如下错误 Packet for query is too large (1185 > 1024). You can change this value on the server by setting the max_allowed_packet' variable.... 按网上要求,检查max_allowed_packet show VARIABLES like '%max_allowed_packet%'; 修改max_allowed_packet set glo

MySQL报错:Ignoring query to other database的解决办法

原因是在登陆数据库的时候,缺少了-u参数 错误截图:修正截图: 原文地址:http://blog.51cto.com/13587182/2074003