MySQL received a network packet larger than the max_allowed_packet limit. Increase max_allowed_packet in your MySQL configuration to handle larger queries, database imports, or BLOB data uploads.
MySQL enforces a maximum size limit on network packets transmitted between the client and server to prevent resource exhaustion and network overload. The max_allowed_packet system variable controls this limit (default 4MB, maximum 1GB). When a packet exceeds this limit, MySQL sends ERROR 1064 and terminates the connection. This error occurs during large SQL dumps, bulk INSERT/UPDATE statements with substantial data, BLOB/TEXT field uploads, or API payloads containing large binary content.
Log into your MySQL server and run:
SHOW VARIABLES LIKE "max_allowed_packet";The result shows the current limit in bytes. For example:
- 4194304 = 4MB (default)
- 16777216 = 16MB
- 67108864 = 64MB
Note this value to compare against your actual packet needs.
Measure your largest SQL dump or payload:
# Check file size
ls -lh your_dump.sql
# Get exact byte count
wc -c your_dump.sql
# For application data, check logs or estimate:
# Large WooCommerce exports: 100-500MB
# Media-rich applications: 256MB+
# Standard business apps: 50-100MBA practical recommendation: set max_allowed_packet to 256MB for most production systems.
Connect to MySQL and run:
SET GLOBAL max_allowed_packet = 256 * 1024 * 1024; -- 256MB
SET SESSION max_allowed_packet = 256 * 1024 * 1024;Verify it took effect:
SHOW VARIABLES LIKE "max_allowed_packet";Warning: This change resets when MySQL restarts. Use only for testing or one-time operations.
Edit your MySQL configuration file:
# Linux/macOS
sudo nano /etc/mysql/my.cnf
# Or
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
# Windows
notepad "C:\ProgramData\MySQL\MySQL Server 8.0\my.ini"Locate the [mysqld] section and add (or update):
[mysqld]
max_allowed_packet = 256M
net_buffer_length = 16M
[mysql]
max_allowed_packet = 256MSave the file and restart MySQL:
# Linux/macOS
sudo systemctl restart mysql
# or
brew services restart mysql
# Windows (PowerShell as Admin)
net stop MySQL80
net start MySQL80If you only need to import a large dump once, pass max_allowed_packet to the client tool:
mysql --max_allowed_packet=256M -u root -p database_name < huge_dump.sql
# Or with mysqldump
mysqldump --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 temporary needs.
Re-run your import or operation:
mysql --max_allowed_packet=256M -u root -p database_name < dump.sqlIf it succeeds, the error is resolved. If the error persists:
- Increase to 512MB: --max_allowed_packet=512M
- Check if your file or query is genuinely larger than expected
- Review application logs to confirm packet sizes being sent
For application-level errors, update your connection string or database driver settings if they support max_allowed_packet configuration.
Memory Safety: MySQL only allocates max_allowed_packet memory when needed, making it safe to set high values (512MB–1GB) on modern systems. Replication: In MySQL replication setups, ensure both master and replica have identical max_allowed_packet values to prevent sync failures. Cloud Databases: For AWS RDS, Aurora, Azure Database for MySQL, or Google Cloud SQL, modify the parameter group or instance settings in the console rather than my.cnf. Connection Drivers: Node.js (mysql2, Sequelize), PHP (mysqli), Python (mysql-connector, SQLAlchemy) may support max_allowed_packet in connection strings—configure once rather than per-query. Optimization Strategy: Rather than always increasing max_allowed_packet, consider splitting large imports into smaller files or using batch INSERT operations within the limit. Stream large BLOBs in chunks within your application. Docker/Kubernetes: Pass max_allowed_packet via MYSQL_INIT_COMMAND environment variable or mount a custom my.cnf file. Error 1153: Very similar to ERROR 1064 "Packet too large"—both indicate exceeding max_allowed_packet, though 1153 is more common in modern versions. Prevention: During development, configure max_allowed_packet to match your production environment to catch packet size issues before deployment.
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