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是否编辑成功
1、使用 service 启动:service mysqld restart
2、使用 mysqld 脚本启动:/etc/inint.d/mysqld restart
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix