MySQL rejected a data packet that exceeds the max_allowed_packet limit. Increase the max_allowed_packet setting in your MySQL configuration or pass it as a command-line option to handle larger queries, BLOB uploads, or database dumps.
MySQL enforces a maximum size limit on individual network packets exchanged between the client and server. This limit, controlled by the max_allowed_packet system variable, prevents network overload and resource exhaustion. When your application sends a query, INSERT statement, or binary data that exceeds this limit, MySQL rejects it with ERROR 1153 and closes the connection. This commonly occurs during large INSERT/UPDATE operations, database imports, BLOB field handling, or mysqldump restoration.
Log into MySQL and run:
SHOW VARIABLES LIKE "max_allowed_packet";Note the current value in bytes (e.g., 16777216 = 16MB, 67108864 = 64MB). This helps you determine how much to increase it.
Check your largest SQL file or BLOB size:
# For SQL dump files
ls -lh your_dump.sql
wc -c your_dump.sql
# Or estimate based on your use case
# Example: 100MB for large WooCommerce dumps, 256MB for media-heavy appsA safe approach is to set max_allowed_packet to 256M or higher for production systems handling substantial data.
For immediate relief without restarting MySQL:
SET GLOBAL max_allowed_packet = 256 * 1024 * 1024; -- 256MB
SET GLOBAL net_buffer_length = 16 * 1024 * 1024; -- 16MBVerify the change:
SHOW VARIABLES LIKE "max_allowed_packet";Note: This resets when MySQL restarts, so use it only for temporary fixes or testing.
Edit your MySQL configuration file (my.cnf or my.ini, typically at /etc/mysql/my.cnf or C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini):
[mysqld]
max_allowed_packet = 256M
net_buffer_length = 16M
[mysql]
max_allowed_packet = 256MNote: Both [mysqld] (server) and [mysql] (client) sections need the setting if you're importing via command-line. Restart MySQL:
# Linux/Mac
sudo systemctl restart mysql
# Or on macOS with Homebrew
brew services restart mysql
# Windows
net stop MySQL80
net start MySQL80If you only need to import a one-time large dump, pass max_allowed_packet to the client:
mysql --max_allowed_packet=256M -u root -p database_name < huge_dump.sqlFor mysqldump restoration:
mysqdump --max_allowed_packet=256M -u root -p database_name > backup.sql
mysql --max_allowed_packet=256M -u root -p database_name < backup.sqlThis avoids permanent configuration changes for one-off operations.
Re-run your import or query:
mysql --max_allowed_packet=256M -u root -p database_name < dump.sqlIf it succeeds, the error is resolved. If it still fails:
- Increase to 512M or 1G: --max_allowed_packet=512M
- Check if your query or file is truly larger than expected
- Review application logs for the exact packet size being sent
For persistent application errors, update your application connection string or driver configuration if it supports max_allowed_packet parameters.
Memory Allocation: MySQL allocates max_allowed_packet memory only when needed, so setting it high (512M–1G) is generally safe for modern systems. Replication: If using MySQL replication, ensure both the source and replica have matching max_allowed_packet values to avoid sync failures. Cloud Databases: For RDS, Aurora, or managed MySQL, update the parameter group (not my.cnf). Use AWS RDS console or equivalent to modify max_allowed_packet. Optimization: Rather than always increasing max_allowed_packet, consider chunking large imports into smaller SQL files or using batch INSERT statements within the limit. For applications, stream large BLOBs in chunks instead of sending entire objects in one query. Docker/Containers: If using MySQL in Docker, pass the option via MYSQL_INIT_COMMAND or mount a custom my.cnf. Testing: In development, set max_allowed_packet to match production values to catch packet size issues early. Connection Pooling: Some application drivers (Node mysql2, PHP mysqli) support max_allowed_packet in connection strings—configure it once rather than per-query.
EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL