max_allowed_packet

Tuning max_allowed_packet variable
May 13, 2025 • Written by ROMAN AGABEKOV
This article is about the max_allowed_packet setting in MySQL, which controls the maximum packet size allowed. It explains the default value and provides several methods to increase this limit, such as using command-line options for the client and server or modifying the configuration file. Increasing this value is important for handling larger queries without errors.

Basic Details

The max_allowed_packet is the maximum size of a MySQL network packet that can be read or created by the server. The parameter comes with a default, minimum, and maximum values that you can change according to your requirements.

Releem automatically tunes 44 variables to improve MySQL performance. Try Releem for Free, or deepen your understanding by reading our detailed article.

max_allowed_packet – Usage

There are several ways of changing the max_allowed_packet value. It is primarily set to the default value, which is 16MB.

To change it, follow this:
$> mysql --max_allowed_packet=32M

This will set the client's value to 32 MB. You can change the value according to your requirements.

Changing the server value is also important, especially when you are dealing with large queries. Usually, the server's default value is 16 MB.
Let's double the server's value, as we did to the client's program:
$> mysqld --max_allowed_packet=32M

Lastly, you can also set the value using an configuration file. Here's how it is done:
[mysqld]
max_allowed_packet=32M


This will change the server size to 32 MB, thus enabling it to transfer larger queries without any error.

When is max_allowed_packet Changed?

So, what's the need for changing max_allowed_packet? When a client server receives larger packet bytes, an error occurs. The connection faces ER_NET_PACKET_TOO_LARGE error and closes instantly.

Another error can be Lost Connection to Server During Query Error. It has the same reason, i.e., a large communication packet.

This happens when the set value for max_allowed_packet is less than the size of uploading files. To perform the transaction successfully, you would have to change the value in both client and server.
FAQ:
MySQL max_allowed_packet
What is max_allowed_packet in MySQL?
It’s the maximum size of a single communication packet that MySQL can handle. It impacts how large a query or result set can be.

What is the default value of max_allowed_packet?
By default, it’s 64MB in MySQL 8.0+, but it can be lower in earlier versions or specific configurations.

How to check the current max_allowed_packet value?
Run:
SHOW VARIABLES LIKE 'max_allowed_packet';

How do I increase max_allowed_packet in MySQL?
Add or modify this line in your MySQL config file (my.cnf or my.ini):
max_allowed_packet = 256M

Then restart MySQL.

Can I set max_allowed_packet dynamically?
Yes, use:
SET GLOBAL max_allowed_packet = 256 * 1024 * 1024;

Note: It resets on restart unless configured in the file.

What’s the recommended value for max_allowed_packet?
Set it just above the largest expected BLOB or query size. Common safe values are 128M–512M. Avoid overly large settings unless necessary.

Does max_allowed_packet affect mysqldump?
Yes. If a row or command exceeds the limit, mysqldump will fail. Use the --max_allowed_packet option when running it.

How does max_allowed_packet relate to ORMs like Laravel or Drupal?
Applications using ORMs may generate large INSERT/UPDATE queries. A low max_allowed_packet can cause “Packet too large” errors.

What happens if max_allowed_packet is too low?
You may see errors like MySQL server has gone away or Packet too large, especially with large queries or BLOB uploads.

Can I change max_allowed_packet for just one session?
Yes. Use:
SET SESSION max_allowed_packet = 128 * 1024 * 1024;
Releem automatically identifies MySQL performance issues, tunes configuration and optimizes SQL queries