MariaDB max_allowed_packet is a system variable that defines the maximum size a single data packet can be during com­mu­ni­ca­tion between the database server and an ap­pli­ca­tion. Without adjusting this limit, large file transfers, bulk inserts or long SQL commands can quickly fail.

What is MariaDB max_allowed_packet?

The max_allowed_packet system variable is a key con­fig­u­ra­tion setting in both MariaDB and MySQL. It specifies the largest single data packet that a client, such as an ap­pli­ca­tion, tool or SQL script, can send to or receive from the MariaDB server. The default value depends on the operating system, dis­tri­b­u­tion and MariaDB version.

A data packet in MariaDB contains SQL state­ments and related content exchanged between the client and server. If a command — for instance, a large INSERT statement with many values or a BLOB (Binary Large Object) — exceeds the allowed size, the server rejects it. In such cases, you’ll often see the error:

ERROR 1153 (08S01): Got a packet bigger than 'max_allowed_packet' bytes
sql

This limit prevents oversized requests from consuming excessive resources or desta­bi­liz­ing the server. At the same time, ad­min­is­tra­tors can adjust it to suit their workload.

Both the server and the client have their own max_allowed_packet value. For a transfer to succeed, both sides must allow packets of the required size. For example, if the server is set to 64 MB but the client is limited to 16 MB, any packet over 16 MB will still fail.

Compute Engine
The ideal IaaS for your workload
  • Cost-effective vCPUs and powerful dedicated cores
  • Flex­i­bil­i­ty with no minimum contract
  • 24/7 expert support included

What does the syntax for MariaDB max_allowed_packet look like?

You can change max_allowed_packet either tem­porar­i­ly or per­ma­nent­ly. The syntax depends on the scope of the ad­just­ment:

Temporary change for the current session

To change the value only for the active con­nec­tion, set it at the session level:

SET SESSION max_allowed_packet = 67108864;
sql

This increases the limit to 64 MB, but only for the current client con­nec­tion.

Global change at runtime

To apply the change for all new con­nec­tions until the server restarts, set it globally:

SET GLOBAL max_allowed_packet = 67108864;
sql

This updates the limit for all future con­nec­tions, but existing sessions remain unchanged.

What are some typical use cases for max_allowed_packet?

In many scenarios, the default value of max_allowed_packet is too low. Setting it higher can prevent errors and in­ter­rup­tions, es­pe­cial­ly in data-heavy op­er­a­tions. The following use cases show where an ad­just­ment is advisable:

  • Importing large SQL dumps: Restoring backups or dumps with sub­stan­tial amounts of data often requires a higher packet size to avoid failures.
  • Pro­cess­ing large BLOBs: Storing binary files such as PDFs, images or archives in the database often exceeds the default limit.
  • Bulk INSERTs with many values: ETL processes or mass uploads that insert large datasets in a single statement can trigger the packet limit.
  • Web ap­pli­ca­tions with large forms or uploads: Frame­works that au­to­mat­i­cal­ly generate large SQL state­ments often hit the packet limit without ad­just­ment.

Avoid setting max_allowed_packet un­nec­es­sar­i­ly high, as it increases memory usage and can impact stability. For most pro­duc­tion en­vi­ron­ments, a value between 16M and 64M is suf­fi­cient. Higher values are typically only needed for tasks like mi­gra­tions.

Example use of max_allowed_packet

Suppose your web ap­pli­ca­tion allows users to upload PDF files up to 64 MB into the database. If the default is 4 MB, the upload will fail. To ensure re­li­a­bil­i­ty, you’ll need to increase the value:

On Linux, open the file /etc/mysql/my.cnf or my.ini if you are using Windows. Under [mysqld], add the following entry:

max_allowed_packet=64M
txt

Restart the MariaDB server:

sudo systemctl restart mariadb
bash

Check the new value:

SHOW VARIABLES LIKE 'max_allowed_packet';
sql

The expected output:

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

Your ap­pli­ca­tion can now handle data packets up to 64 MB without errors, improving stability and allowing smooth operation even with larger transfers.

Managed Databases
Time-saving database services
  • En­ter­prise-grade ar­chi­tec­ture managed by experts
  • Flexible solutions tailored to your re­quire­ments
  • Leading security in ISO-certified data centers
Go to Main Menu