max_allowed_packet

MySQL max_allowed_packet variable tuning

Written By ROMAN AGABEKOV | NOV 21, 2021

Last update | SEP 10, 2026

max_allowed_packet limits the size of an individual MySQL communication packet, such as a statement sent to the server or a row returned to a client. A large total result set is not necessarily one oversized packet. Check both endpoints before treating this as a server-setting problem.

Check the current packet limit

These checks apply to Oracle MySQL 8.4. Other releases and client libraries can have different defaults.
SELECT VERSION() AS server_version,
       @@version_comment AS vendor_build,
       @@GLOBAL.max_allowed_packet AS global_limit_bytes,
       @@SESSION.max_allowed_packet AS session_limit_bytes;
The two limits are server-side values in bytes. This query does not report your application's client-library limit. MySQL 8.4 has a server default of 64 MiB, but an existing installation may use another value. Read the current values rather than assuming a default.
The session value is read-only: SET SESSION max_allowed_packet is not supported. New connections inherit the global value; changing the global value does not update an existing connection's session value. Coordinate configuration changes with your DBA and connection-pool lifecycle.

Identify the error before changing a setting

When a receiver gets a packet beyond its permitted size, MySQL can report ER_NET_PACKET_TOO_LARGE and close the connection. A generic lost-connection error has other possible causes, so preserve the exact error code and check the server log.
A string-generating expression can instead exceed the permitted result size, return NULL, and produce a warning. That is not the same as a rejected network packet and does not by itself mean that the connection closed.
For an import or export, record the exact client and version too. A mysqldump help-text default alone does not establish its effective packet limit: Oracle MySQL 8.4's enabled-by-default --network-timeout option changes that behavior. Verify the options for the client actually running the operation.

Avoid a universal packet-size recommendation

There is no generally safe 128-512 MiB recommendation for every workload. Identify the failing operation, the relevant endpoint and its effective limit first. Increasing a limit does not resolve timeouts, network failures or unrelated memory pressure.
For broader investigation, use the MySQL health-check workflow. For configuration review, see MySQL configuration tuning with Releem.

Sources