情况出现情景:
在SpringBoot+mybatis+mysql5.5的环境上进行查询数据,要查询(通过很多编号进行查询,一个编号有5-12位不等的编号)的数据太多。
报错如下:
### Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (3396053 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable. ; SQL []; Packet for query is too large (3396053 > 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 (3396053 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.] with root cause com.mysql.jdbc.PacketTooBigException: Packet for query is too large (3396053 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
分析错误:
重要的提示:
Packet for query is too large (3396053 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
大概意思是:
用于查询的包太大,您可以通过设置’max_allowed_packet’变量来更改服务器上的这个值。
通过网上查资料了解到,mysql默认加载的数据文件不超过1M。只能通过修改配置文件来解决。
那么’max_allowed_packet’变量是哪里的呢?
答案:
mysql中的
打开mysql命令行
输入命令
set @@max_allowed_packet=16*1024*1024
报错了,说:变量’max_allowed_packet’是只读的。使用SET GLOBAL分配值
解决方案:
SET GLOBAL max_allowed_packet=16*1024*1024
成功了。
第一种办法不行,就用第二种。第二种不行就用第一种。