MariaDB max_allowed_packet Explained: Configuration, Packet Size, and Best Practices

Published: 2026-07-15

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

Operating System : AlmaLinux 10
PHP Version      : PHP 8.3
Web Server       : Nginx
PHP-FPM          : Enabled
Architecture     : x86_64
Last Tested      : July 2026

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:

SHOW VARIABLES LIKE 'max_allowed_packet';

Example output:

+---------------------+----------+
| Variable_name       | Value    |
+---------------------+----------+
| max_allowed_packet  | 67108864 |
+---------------------+----------+

The value is displayed in bytes. In this example, 67,108,864 bytes equals 64 MB.

How It Works

Application
      │
      ▼
SQL Query / File Upload
      │
      ▼
MariaDB
      │
 ┌────┴─────┐
 │          │
Within      Too Large
Limit       │
 │           ▼
 ▼      Reject Request
Accept      Error

MariaDB checks the packet size before processing the request.

Check the Current Value

SHOW VARIABLES LIKE 'max_allowed_packet';

To display the value in megabytes:

SELECT @@max_allowed_packet / 1024 / 1024 AS MB;

Example:

+------+
| MB   |
+------+
| 64   |
+------+

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

SHOW VARIABLES LIKE 'max_allowed_packet';

Recommended Values

| Workload                 | Suggested Value |
| ------------------------ | --------------- |
| Development              |             32M |
| WordPress                |             64M |
| Laravel                  |             64M |
| General Web Applications |        64M–128M |
| Large BLOB Storage       |           256M+ |
| Database Import/Export   |       128M–512M |

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.

Application
      │
      ▼
MariaDB Client
      │
      ▼
MariaDB Server

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 Explained

MariaDB max_connections Explained

MariaDB innodb_buffer_pool_size Explained

MariaDB wait_timeout Explained

PHP upload_max_filesize Explained

PHP post_max_size 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

Technology Guides →

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

Southeast Asia Insights →

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