How to fix ERROR 1064: Packet too large in MySQL

MySQLINTERMEDIATEHIGHUpdated Dec 25, 2025· 258 views

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.

Quick fix

Fixes 1064

SHOW VARIABLES LIKE "max_allowed_packet";
  1. Check the current max_allowed_packet setting
  2. Determine the required packet size
  3. Apply a temporary fix (for immediate testing)
  4. Make a permanent fix via my.cnf configuration
mysql — error
SHOW VARIABLES LIKE "max_allowed_packet";
ERROR 1064: Packet too large

What this error means

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.

Typical symptoms

  • Database import fails partway through large dump files
  • Large INSERT statements are rejected unexpectedly
  • BLOB uploads fail with connection dropped
  • mysqldump restoration stops with packet size error
  • Bulk API requests fail when posting large data
  • Web applications cannot save large files or metadata

Common causes

  1. The max_allowed_packet value is too small for the data being sent
  2. Importing SQL dumps with row sizes exceeding the limit
  3. Bulk INSERT statements containing row data larger than max_allowed_packet
  4. Large BLOB or TEXT field data in a single query
  5. Client-side and server-side max_allowed_packet values mismatch
  6. Network buffer exhausted by oversized payloads

How to fix "ERROR 1064: Packet too large"

1Check the current max_allowed_packet setting

Log into your MySQL server and run:

sql
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.

2Determine the required packet size

Measure your largest SQL dump or payload:

bash
# 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-100MB

A practical recommendation: set max_allowed_packet to 256MB for most production systems.

3Apply a temporary fix (for immediate testing)

Connect to MySQL and run:

sql
SET GLOBAL max_allowed_packet = 256 * 1024 * 1024;  -- 256MB
SET SESSION max_allowed_packet = 256 * 1024 * 1024;

Verify it took effect:

sql
SHOW VARIABLES LIKE "max_allowed_packet";

Warning: This change resets when MySQL restarts. Use only for testing or one-time operations.

4Make a permanent fix via my.cnf configuration

Edit your MySQL configuration file:

bash
# 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):

ini
[mysqld]
max_allowed_packet = 256M
net_buffer_length = 16M

[mysql]
max_allowed_packet = 256M

Save the file and restart MySQL:

bash
# Linux/macOS
sudo systemctl restart mysql
# or
brew services restart mysql

# Windows (PowerShell as Admin)
net stop MySQL80
net start MySQL80
5For one-off imports, use command-line options

If you only need to import a large dump once, pass max_allowed_packet to the client tool:

bash
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.sql

This avoids permanent configuration changes for temporary needs.

6Verify the fix resolves the error

Re-run your import or operation:

bash
mysql --max_allowed_packet=256M -u root -p database_name < dump.sql

If 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.

Advanced notes

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.

Frequently asked questions

What does "1064" mean?
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.
How do I fix "1064"?
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.
What causes "1064"?
The max_allowed_packet value is too small for the data being sent Importing SQL dumps with row sizes exceeding the limit Bulk INSERT statements containing row data larger than max_allowed_packet
Is the "1064" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading