Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (16944839 > 16777216). You can change this value on the server by setting the max_allowed_packet' variable.

今天发现task微服务的error日志报如下错误:

Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (16944839 > 16777216). You can change this value on the server by setting the max_allowed_packet' variable.

网上查了一下说要设置  max_allowed_packet    但是我查了一下现在已经是100M了

show variables like '%max_allowed_packet%'

然后我重启mysql和重启task微服务还是报这个错,后来又有个文章说要设置 mysql 连接的url 加上 

&useServerPrepStmts=true&maxAllowedPacket=104857600


然后我重启了task微服务又报另外一个错,如下

2019-11-08 12:53:19.580 pool-9-thread-25 ERROR com.hp.nova.common.tasksync.tcscheduler.TcFileProcessScheduleJob.fileProcessCronJob(TcFileProcessScheduleJob.java:354) - org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='__frch_i_8241.stepStatus', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #24726 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of bounds. 24726 is not between valid values of 1 and 24725

如果改成只加如下一个配置,就还是不生效

maxAllowedPacket=104857600

后面没办法没找到原因为什么max allowed packet设置了task微服务还是报错不能超过16M,后面只能修改了源代码把批量update的语句改成了每1000条update一次解决了问题

 
 
原文地址:https://www.cnblogs.com/xiaohanlin/p/11821977.html