MySQL异常:com.mysql.jdbc.PacketTooBigException: Packet for query is too large

### Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1169 > 1024). You can change this value on the server by setting the max_allowed_packet' variable.; SQL []; Packet for query is too large (1169 > 1024). 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 (1169 > 1024). You can change this value on the server by setting the max_allowed_packet' variable.

The reason is that the max_allowed_packet setting of MySQL is too small. I set it to 1M at first, and then changed it to 20M

According to the configuration file, mysql will limit the size of the data packet accepted by the server. Sometimes large inserts and updates are limited by the max_allowed_packet parameter, resulting in failure.

Enter the mysql command

1: Enter the installation directory first, then enter mysql -u root -p, and then enter the password

 

Execute commands on the mysql command line

1. View the current configuration

  show VARIABLES like '%max_allowed_packet%';

  

2. Modify the configuration

  set global max_allowed_packet = 2*1024*1024*10;
modify the value of max_allowed_packet to a larger value, and mysql restarts the service after the modification is completed, but the project may also be restarted.

3. Under the Linux system

  Under linux, go to the mysql installation directory:

  Enter:

    /usr/local/mysql, find my.cnf, add a line

    max_allowed_packet = 20M

  restart mysql:

    service mysql restart

Guess you like

Origin blog.csdn.net/qq_33551131/article/details/88772294