MariaDB max_allowed_packet Explained: Configuration, Packet Size, and Best Practices
Introduction
The max_allowed_packet system variable specifies the maximum size of a single communication packet that MariaDB accepts from a client.
A packet may contain an SQL statement, a query result, or binary data such as images, documents, or other large objects. If the packet exceeds the configured limit, MariaDB rejects the request and returns an error.
Choosing an appropriate packet size is important for applications that import databases, upload large files, or store BLOB and TEXT data.
This guide explains how max_allowed_packet works, how to configure it, recommended values, and common configuration mistakes.
Test Environment
What Is max_allowed_packet?
The max_allowed_packet variable defines the largest packet that MariaDB will accept from a client.
View the current value:
Example output:
The value is displayed in bytes. In this example, 67,108,864 bytes equals 64 MB.
How It Works
MariaDB checks the packet size before processing the request.
Check the Current Value
To display the value in megabytes:
Example:
Change max_allowed_packet
Edit the MariaDB configuration file.
sudo nano /etc/my.cnf
Example:
[mysqld]
max_allowed_packet = 128M
Save the file.
Restart MariaDB
Apply the new configuration.
sudo systemctl restart mariadb
Verify the service:
sudo systemctl status mariadb
Expected output:
Active: active (running)
Verify the New Value
Recommended Values
Use the smallest value that comfortably supports your application's requirements.
Common Errors
Packet Too Large
Typical error:
ERROR 1153 (08S01):
Got a packet bigger than 'max_allowed_packet' bytes
This occurs when a client sends data larger than the configured limit.
MySQL Server Has Gone Away
Another common message is:
MySQL server has gone away
Although this error has several possible causes, an oversized packet is one of the most common.
Other causes include:
Connection timeouts
Network interruptions
Server crashes
Always check the MariaDB error log before assuming that max_allowed_packet is the problem.
Large SQL Import Fails
Importing a database dump that contains large INSERT statements may fail if the packet size is too small.
Increasing max_allowed_packet often resolves this issue.
Relationship with Client Settings
Both the MariaDB server and the client application must support the packet size.
If either side imposes a smaller limit, large packets may still fail.
Best Practices
Configure the packet size according to your application's needs.
Avoid unnecessarily large values unless required.
Check the MariaDB error log when packet-related errors occur.
Restart MariaDB after modifying the configuration.
Test large imports and uploads after making changes.
Related Articles
MariaDB max_connections Explained
MariaDB innodb_buffer_pool_size Explained
MariaDB wait_timeout Explained
PHP upload_max_filesize Explained
Conclusion
The max_allowed_packet variable controls the maximum size of a packet that MariaDB accepts from client applications. It plays an important role when importing databases, storing large objects, and processing large SQL statements.
For most production environments, a value between 64 MB and 128 MB provides a practical balance between flexibility and resource usage. When packet-related errors occur, review both server and client settings, and confirm the root cause before increasing the limit.
Explore More
› MariaDB Explained: Essential Configuration Variables and Best Practices
› MariaDB max_connections Explained: Configuration, Limits, and Best Practices
› MariaDB innodb_buffer_pool_size Explained: Memory, Performance, and Best Practices
› MariaDB wait_timeout Explained: Idle Connections, Timeouts, and Best Practices
› Best Areas to Live in Bangkok in 2026: A Complete Guide for Expats and Digital Nomads
› Best Coworking Spaces in Bangkok 2026: A Guide for Digital Nomads and Remote Workers
› Why Do People in Southeast Asia Love Iced Drinks? The Climate, Culture, and Science Explained
› Best eSIM for Southeast Asia in 2026: Compare the Top Travel eSIMs