问题描述

查询或插入的数据包大于MySQL默认设置


com.mysql.cj.jdbc.exceptions.PacketTooBigException: Packet for query is too large (12,131,066 > 4,194,304). 
You can change this value on the server by setting the 'max_allowed_packet' variable.

ERROR 2020 (HY000): Got packet bigger than 'max_allowed_packet' bytes


问题解决

## 查询系统字符集
SHOW VARIABLES LIKE '%character%';
## 查询MySQL接收数据表的大小
SHOW VARIABLES LIKE '%max_allowed_packet%';
## 方法1、设置为1g
SET GLOBAL max_allowed_packet = 1*1024*1024*1024;
SET GLOBAL slave_max_allowed_packet = 1*1024*1024*1024;
## 方法2、修改my.cnf配置文件
max_allowed_packet = 1g
slave_max_allowed_packet = 1g
## 重启mysql服务
service mysql restart
## 设置完之后退出登录重新查看
SHOW VARIABLES LIKE '%max_allowed_packet%';