上线项目报错,动不动就网络异常,连接不上,查看后发现出错
com.mysql.cj.jdbc.exceptions.PacketTooBigException: Packet for query is too large (4,867 > 1,024). You can change this value on the server by setting the 'max_allowed_packet' variable.
解决办法:
set global max_allowed_packet = M
重新设置 max_allowed_packet 大小 M是你要设置的大小
重启MYSQL(Windows下不能直接重启(restart),只能先停止,再启动。)
net stop mysql net start mysql
查看一下,修改完成 show VARIABLES like '%max_allowed_packet%';
解决OK,找原因
MySQL根据配置文件会限制server接受的数据包大小。
有时候大的插入和更新会被max_allowed_packet 参数限制掉,导致失败。
点滴积累,可成大海