Increase the MySQL max allowed packet size
The max_allowed_packet
variable sets the maximum size of a single
query packet that MySQL can process.
If you encounter “Packet too large” errors, increasing
max_allowed_packet
may help resolve the issue.
Ensure you set this value appropriately based on workload requirements. Setting it too high can lead to excessive memory usage.
The default value is 64MB in MySQL 8.0. If you experience issues, try increasing the value to 128MB or higher based on your needs.
Change max_allowed_packet
Create the file:
/etc/mysql/conf.d/max_allowed_packet.cnf
with the following contents (replace VALUE with the desired size).
[mysqld]max_allowed_packet = VALUE
VALUE can be:
- An integer number of bytes.
- An integer with the suffix
K
,M
, orG
(case-insensitive) for kilobytes, megabytes, or gigabytes.
For example, the following sets the max allowed packet size to 128 megabytes.
[mysqld]max_allowed_packet = 128M
After creating the file, restart MySQL.
sudo service mysql restart
Confirm the new value with the following command:
sudo mysql -e "SHOW VARIABLES LIKE 'max_allowed_packet';"