HOWTO · MySQL

How to Change the max_allowed_packet Size in the MySQL Server

Learn how to check and change the MySQL max_allowed_packet setting temporarily or persistently on Windows and Ubuntu.

On this page

A Packets larger than max_allowed_packet are not allowed error can occur when a client or server encounters a packet larger than its configured limit. The client and server each have their own max_allowed_packet setting, so changing one does not necessarily change the other. This guide shows how to inspect the server value, change it for the current server session, and make a persistent server-side change on Windows or Ubuntu. The MySQL reference describes the packet-too-large condition and the separate client and server limits.

Understand max_allowed_packet and choose a value

max_allowed_packet limits the size of a communication packet the MySQL client or server can handle. Choose a value large enough for the largest statement or data item your application sends, while considering memory use and your deployment’s policy. Do not assume a value shown by one installation is a universal default.

The value is measured in bytes. For example, 50 MiB is 52,428,800 bytes. This small Python example converts that size to bytes; it is a unit conversion and does not contact MySQL.

Run this example:

print(50 * 1024 * 1024)
52428800

Check the current client and server values

Connect to the MySQL server and run SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'; to inspect the global server value. SHOW VARIABLES LIKE 'max_allowed_packet'; reports the session value where applicable, so use the global query when checking the server-wide setting. The result is a byte count; for instance, 4194304 bytes is 4 MiB. Treat that number as an example, not as a promised default.

A server query does not tell you the setting used by every client program. Check the relevant client’s options separately if the error persists after adjusting the server. MySQL option files can use [mysqld] for the server, [client] for general client programs, or [mysql] for the command-line client. The setting in a client group applies to clients that read that group; it does not replace the server setting.

Change the server value temporarily with SQL

A runtime change is useful for a quick diagnosis or temporary adjustment. Connect with an account that has the privilege required by your MySQL server version and configuration; the exact privilege requirements can vary. Then run SET GLOBAL max_allowed_packet = 52428800; to set the illustrative 50 MiB value. Check the result with SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet';.

A global change affects new connections; reconnect before checking behavior from a client session that may retain session settings. A runtime change is not a substitute for persistent configuration: it may be lost when the server restarts. If your account cannot run the statement, ask an administrator with the appropriate privilege to apply it.

Persist the server setting in the MySQL configuration file

To keep the server value after restart, edit the option file MySQL actually reads and place the setting under [mysqld], for example max_allowed_packet=50M. If the option already exists in that group, update it instead of adding a conflicting duplicate. A setting under [client] or [mysql] configures clients, not the server.

The option-file location and service name depend on the installation. Back up or otherwise preserve the existing file, then restart the MySQL service when required for its configuration to take effect. Verify the active value after the restart with SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet';. If it differs from the configured value, confirm that you edited the file read by that server instance and used the correct group.

Apply and verify the setting on Windows

For a default MySQL Server 8.0 installation, the command-line client may be under C:\Program Files\MySQL\MySQL Server 8.0\bin, and the option file may be C:\ProgramData\MySQL\MySQL Server 8.0\my.ini. These are example paths; use the paths for your installation if they differ.

Open Command Prompt and change to the installed bin directory, or invoke mysql.exe by its full path. Sign in with mysql -u root -p; the client prompts for the password, so it is not exposed in the command text. Use an account with the required administrative privilege for a temporary SQL change, then run SET GLOBAL max_allowed_packet = 52428800; and verify with SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet';.

For a persistent change, open the applicable my.ini, find [mysqld], and add or update max_allowed_packet=50M beneath it. Save the file and restart the MySQL service using the service controls available on your system. Reconnect and check the global value. If the packet-too-large error remains, inspect the client setting as well as the server value.

Apply and verify the setting on Ubuntu

On Ubuntu, a common server option-file path is /etc/mysql/mysql.conf.d/mysqld.cnf; package, container, and custom installations may use another file. To edit that example path, use sudoedit /etc/mysql/mysql.conf.d/mysqld.cnf or an editor available on your system. Under [mysqld], add or update max_allowed_packet=70M if that is an appropriate limit for your workload. This example is 73,400,320 bytes.

Save the file, then restart the service if your installation uses the mysql systemd unit, for example with sudo systemctl restart mysql. Service names and restart procedures can differ. Reconnect and run SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'; to verify the active server value. For a temporary change instead, connect to MySQL and use SET GLOBAL max_allowed_packet = 73400320;, provided the account has the required privilege; confirm it with the same global query.

If the error continues, compare the packet size with both the server’s global value and the setting used by the client that sends the data. Also check that the server restarted successfully and loaded the option file and [mysqld] entry you changed. The paths and sample limits above are starting points to adapt to the actual installation and workload.