django.db.utils.InternalError: (1153, "Got a packet bigger than 'max_allowed_packet' bytes")

created at 07-27-2021 views: 21

Encountered an error when writing data:

django.db.utils.InternalError: (1153, "Got a packet bigger than 'max_allowed_packet' bytes")

reason

After querying that the max_allowed_packet value is set too small, mysql reports an error, limiting the size of the data packet accepted by the server.

Enter the mysql console through the terminal

mysql -hlocalhost -uroot -p

Enter the following command to view the value of max_allowed_packet.

show VARIABLES like '%max_allowed_packet%';

max_allowed_packet    1024
slave_max_allowed_packet    1073741824

The current mysql max_allowed_packet size is 1k

Modification method

1. Temporary modification method is only applicable to mysql without restarting, once the restart configuration information becomes invalid.

# set to 10m
set global max_allowed_packet = 1048576*10

2. Modify the my.cnf configuration file (after restarting the mysql service, it will take effect permanently)

max_allowed_packet=20M

mysql command

The mysql command is as follows:

startup

  1. Start using service: service mysqld start
  2. Use the mysqld script to start: /etc/inint.d/mysqld start
  3. Start with safe_mysqld: safe_mysqld&

stop

  1. Start using service: service mysqld stop
  2. Use the mysqld script to start: /etc/inint.d/mysqld stop
  3. mysqladmin shutdown

restart

  1. Start using service: service mysqld restart
  2. Use the mysqld script to start: /etc/inint.d/mysqld restart
created at:07-27-2021
edited at: 07-27-2021: