Skip to content
MySQL

MySQL Error 1153

Got a packet bigger than 'max_allowed_packet' bytes

Applies to: MySQL 5.7, 8.0 and 8.4 (server default max_allowed_packet 64 MB in 8.0; largest possible packet 1 GB)
Last technically reviewed 24 October 2026 on MySQL 8.0.46
The full message
ERROR 1153 (08S01): Got a packet bigger than 'max_allowed_packet' bytes
Other forms of this message
PHP PDO
SQLSTATE[08S01]: Communication link failure: 1153 Got a packet bigger than 'max_allowed_packet' bytes
The next statement on the same connection (PHP PDO)
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
mysql client 8.0.46 sending the same statement
ERROR 2013 (HY000) at line 1: Lost connection to MySQL server during query
The client's own limit for data it receives (client error 2020, catalogue text)
Got packet bigger than 'max_allowed_packet' bytes
Error number
1153
SQLSTATE
08S01
Symbol
ER_NET_PACKET_TOO_LARGE
Product
MySQL Server
Versions
MySQL 5.7, 8.0 and 8.4 (server default max_allowed_packet 64 MB in 8.0; largest possible packet 1 GB)
Last reviewed
24 October 2026

What it means

Error 1153 means the server received a single packet, usually one SQL statement, larger than its max_allowed_packet limit, so it rejected it and closed the connection.

Client and server exchange data in packets. A packet is a single SQL statement sent to the server, a single row sent back to the client, or one binary log event sent to a replica. The server refuses any packet larger than max_allowed_packet (64 MB by default in MySQL 8.0), returns 1153 and closes the connection, because it treats an oversized packet as a sign that something went wrong. That is why the error usually comes with a lost connection: the next statement on that connection fails with 2006, and some clients report 2013 instead of 1153 in the first place.

The client side has its own limit for what it receives: the mysql client defaults to 16 MB and mysqldump to 24 MB, while the C client library's built-in default is 1 GB. So a big value may be refused by the server on the way in (1153) or by the client on the way out (client error 2020). The session value of max_allowed_packet is read-only; only the global value, set at runtime or at startup, changes the server limit.

Common causes

  • A single INSERT or UPDATE carries a large BLOB or TEXT value, such as a file, an image or a large JSON document.
  • A multi-row INSERT built by the application or an ORM grows past the limit (thousands of rows in one statement).
  • A dump made with large extended INSERT statements is loaded into a server with a smaller max_allowed_packet than the source.
  • A query returns a row bigger than the client's limit, which the client reports as its own error 2020 rather than 1153.

Diagnose it

Read-only These statements only read metadata (information_schema, performance_schema and SHOW statements) or your own data. They do not change data, privileges or configuration, so they are safe to run first.

The current server limit

SHOW VARIABLES LIKE 'max_allowed_packet';
SELECT @@GLOBAL.max_allowed_packet AS global_bytes,
       @@SESSION.max_allowed_packet AS this_session_bytes;
What to look for

The limit in bytes (67108864 is 64 MB). The session value is copied from the global one when the connection opens and is read-only, so a raised global value applies only to new connections.

How large are the values you store?

SELECT COUNT(*) AS documents,
       MAX(LENGTH(body)) AS largest_bytes,
       ROUND(MAX(LENGTH(body)) / 1048576, 1) AS largest_mb
FROM documents;
What to look for

The largest stored value in the column. A value close to max_allowed_packet cannot be written or read in one statement with much room to spare (the statement text, escaping and other columns add to its size).

Has the server been refusing packets?

SELECT error_number, error_name, sum_error_raised, first_seen, last_seen
FROM performance_schema.events_errors_summary_global_by_error
WHERE error_number = 1153;

SHOW GLOBAL STATUS LIKE 'Aborted_clients';
What to look for

How many times 1153 has been raised since startup and when it was last seen, even if your client showed 2006 or 2013. Aborted_clients rises when a connection ends without being closed properly, which includes connections closed after 1153.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Send smaller statements

Client or network side

Split large multi-row INSERTs into batches (a few hundred or thousand rows each), and keep very large files out of single statements: store them in object storage with a reference in the table, or write them in chunks. This avoids the error without changing the server.

INSERT INTO order_lines (order_id, line_no, product_id, qty) VALUES
  (10, 1, 501, 2),
  (10, 2, 502, 1);  -- send batches like this, not one statement with every row

Raise the client-side limit for dumps and imports

Client or network side

The client programs have their own option. When loading or reading big rows, give both mysqldump and mysql a large enough limit; it only affects that program.

-- mysqldump --max-allowed-packet=256M shop > shop.sql
-- mysql --max-allowed-packet=256M shop < shop.sql

Raise the server limit when you really need bigger packets

Changes configuration

If single values must be larger than 64 MB, raise the global value. SET PERSIST applies it to new connections now and stores it in mysqld-auto.cnf so it survives a restart; SET GLOBAL alone lasts until the next restart; the [mysqld] section of my.cnf is read at startup. The MySQL manual notes that raising it is safe in the sense that extra memory is allocated only when a large packet is actually sent or returned.

Caution: Raise it to what the data needs, not to the 1 GB maximum by default: the limit also protects the server from runaway statements, and every connection that sends a huge packet needs that much memory at once. Existing connections keep their old limit until they reconnect.

SET PERSIST max_allowed_packet = 268435456;  -- 256 MB, for new connections

# or in my.cnf
[mysqld]
max_allowed_packet = 256M

Reconnect after the error

Client or network side

The server closes the connection after 1153, so the application must open a new one. Retrying the same oversized statement fails again; change the statement first.

Examples

One statement larger than the server limit (PHP mysqli)

Captured with PHP 8.2 mysqli (mysqlnd) against MySQL 8.0.46 and shown in the client's ERROR format from errno, SQLSTATE and message. It is a race with the server closing the connection: in our runs the same statement gave 1153 most of the time and 2006 MySQL server has gone away sometimes. The statement is too large to store in the page, so the lab does not rerun it.

SHOW VARIABLES LIKE 'max_allowed_packet';  -- 67108864 (64 MB)

-- From PHP, one statement of about 70 MB:
-- $big = str_repeat('x', 70 * 1024 * 1024);
-- $mysqli->query("SELECT LENGTH('$big') AS len");
Result
ERROR 1153 (08S01): Got a packet bigger than 'max_allowed_packet' bytes

The connection is gone afterwards (PHP PDO)

Captured with PHP 8.2 PDO_MYSQL against MySQL 8.0.46: the first call raised SQLSTATE[08S01]: Communication link failure: 1153 Got a packet bigger than 'max_allowed_packet' bytes, and the next statement on the same connection failed with 2006 because the server had closed it. Not rerun by the lab (needs a 70 MB statement).

-- $pdo->query($seventyMegabyteStatement);  -- fails with 1153
$pdo->query('SELECT 1');
Result
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

The mysql client reports the same problem as 2013

Captured with the mysql 8.0.46 client on Windows, with and without a raised client limit. The server counted the packet as error 1153 (visible in events_errors_summary_global_by_error), but this client only saw the closed connection. The manual mentions this: with some clients you get Lost connection to MySQL server during query instead.

-- big.sql holds one statement of about 70 MB:
-- mysql --max-allowed-packet=128M < big.sql
SELECT LENGTH('xxxx...about 70 MB of text...') AS len;
Result
ERROR 2013 (HY000) at line 1: Lost connection to MySQL server during query

How to prevent it

Design for bounded statements: batch bulk inserts, stream or chunk large files, and give servers that exchange dumps the same max_allowed_packet. Check the size of the largest values in BLOB, TEXT and JSON columns before a migration.

Because the client often sees 2006 or 2013 instead of 1153, watch the server side: error 1153 in performance_schema.events_errors_summary_global_by_error is the reliable sign that packets are too large.

Common questions

How do I fix Got a packet bigger than max_allowed_packet bytes?

Send smaller statements (batch inserts, chunk large values), and for dumps give mysqldump and mysql a larger --max-allowed-packet. If single values truly need more than the server allows, raise the global max_allowed_packet with SET PERSIST or in my.cnf, then reconnect.

Why does SET SESSION max_allowed_packet not work?

The session value of max_allowed_packet is read-only. It is copied from the global value when a connection opens, so change the global value (SET GLOBAL or SET PERSIST, which needs an administrative privilege) and open a new connection.

Why did I get 2006 or 2013 instead of 1153?

The server closes the connection right after rejecting the packet. Depending on timing and the client library, the client may read the 1153 error first or only notice the closed connection, which it reports as 2006 (gone away) or 2013 (lost connection). We saw all three for the same statement.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 24 October 2026; examples and diagnostics run on MySQL 8.0.46. Message templates checked against the server's error catalogue (perror) for that version.

Still stuck on a MySQL error?

Browse the full MySQL error library, or get hands-on help from an experienced SQL professional.