解决 mysql>com.mysql.jdbc.PacketTooBigException: Packet for query is too large (12073681 > 4194304)

com.mysql.jdbc.PacketTooBigException: Packet for query is too large 异常解决办法:

原因: 查询出的数据包过大,默认情况下mysql 的字段容量不够装,所以抛出此异常

解决办法:

第一步:首先通过SQLyog客户端查询框输入以下命令,也可以在cmd命令行窗口下登录mysql后输入以下命令:

SHOW VARIABLES LIKE '%max_allowed_packet%'

;查看当前的最大允许数据包的容量。

默认情况下,最大允许数据包的容量是1M ,需要修改更大一点。改为20M。
默认大小
解决 mysql>com.mysql.jdbc.PacketTooBigException: Packet for query is too large (12073681 > 4194304)
第二步:到mysql 的安装目录下找到 my.ini 文件中,新增

[mysqld]
max_allowed_packet=20M

解决 mysql>com.mysql.jdbc.PacketTooBigException: Packet for query is too large (12073681 > 4194304)
第三步:重启mysql服务
解决 mysql>com.mysql.jdbc.PacketTooBigException: Packet for query is too large (12073681 > 4194304)

查看更改后的结果
解决 mysql>com.mysql.jdbc.PacketTooBigException: Packet for query is too large (12073681 > 4194304)
附上:
解决mysql 8.0出现PacketTooBigException: Packet for query is too large (9248282 > 4194304)

#登录
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -uroot -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.21 MySQL Community Server - GPL

#查看默认大小
mysql> SHOW VARIABLES LIKE '%max_allowed_packet%';
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| max_allowed_packet        | 4194304    |
| mysqlx_max_allowed_packet | 67108864   |
| slave_max_allowed_packet  | 1073741824 |
+---------------------------+------------+
3 rows in set, 1 warning (0.00 sec)

#设置大小
mysql> set global max_allowed_packet = 2*1024*1024*10;

#退出
mysql>exit

#重新启动mysql
 第一种采用上面
 第2种采用命令行
 net mysql stop
 net mysql start 

#重新登录
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -uroot -p
Enter password: ****

#再次查看大小
mysql> SHOW VARIABLES LIKE '%max_allowed_packet%';
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| max_allowed_packet        | 20971520   |
| mysqlx_max_allowed_packet | 67108864   |
| slave_max_allowed_packet  | 1073741824 |
+---------------------------+------------+
3 rows in set, 1 warning (0.01 sec)

mysql>
上一篇:【AVD】用 notepad++ 和 Excel 协助分析媒体文件包


下一篇:输出ppm文件有误,无法显示