Skip to content

Instantly share code, notes, and snippets.

@vyspiansky
Last active March 6, 2025 20:26
Show Gist options
  • Save vyspiansky/904a6f850e094e7957afde5fee4e8cb9 to your computer and use it in GitHub Desktop.
Save vyspiansky/904a6f850e094e7957afde5fee4e8cb9 to your computer and use it in GitHub Desktop.
Set max_allowed_packet size in MySQL

Update MySQL's maximum packet size configuration

We're going to fix the following issue

The query length of 118146958 bytes is larger than max_allowed_packet size (33554432).

First of all, let's check the current size

SHOW VARIABLES LIKE 'max_allowed_packet';

Output:

+--------------------+-----------+
| Variable_name      | Value     |
+--------------------+-----------+
| max_allowed_packet | 33554432  |
+--------------------+-----------+

Note that the value is 33554432 bytes, which is equivalent to 32MB.

Use the MySQL root user to set the desired value in bytes:

mysql -h <DB_HOST> -u root -p <DB_NAME> -e "SET GLOBAL max_allowed_packet=268435456;"

Let's check the size

mysql -h <DB_HOST> -u <DB_USER> -p <DB_NAME> -e "SHOW VARIABLES LIKE 'max_allowed_packet';"

Output:

+--------------------+-----------+
| Variable_name      | Value     |
+--------------------+-----------+
| max_allowed_packet | 268435456 |
+--------------------+-----------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment