Troubleshooting··3 min read

MySQL max_allowed_packet Error: What It Means and How to Fix It

Getting 'Got a packet bigger than max_allowed_packet bytes'? Here's what's actually happening and your options.

You're importing a SQL dump and MySQL throws: 'Got a packet bigger than max_allowed_packet bytes'. The import dies. Now what?

What this error means

MySQL has a limit on how big a single query can be. The default is usually 4MB or 16MB. If your SQL dump has an INSERT statement larger than this limit, MySQL rejects it.

This commonly happens when:

  • You have tables with BLOB/TEXT columns containing large data
  • mysqldump used extended-insert (multiple rows per INSERT)
  • A single table row is just really big

Fix 1: Increase the limit (if you can)

If you have access to my.cnf or can run MySQL commands:

SET GLOBAL max_allowed_packet=256*1024*1024;

Or in my.cnf:

[mysqld]
max_allowed_packet=256M

Then restart MySQL. But on shared hosting, you probably can't do this.

Fix 2: Re-export with smaller inserts

If you still have access to the source database, export again with these flags:

mysqldump --skip-extended-insert --single-transaction database_name > dump.sql

The --skip-extended-insert flag creates one INSERT per row instead of combining them. The file will be bigger, but each query stays small.

Fix 3: Split the existing dump

Don't have access to the source database? You can split the dump file into smaller chunks. Each chunk stays under the packet limit.

Try splitting by size (like 10MB per file) rather than by lines — this directly targets the packet size issue.

Split your SQL dump

Break it into smaller files that won't hit the packet limit.

Open SQLSplit

Checking your current limit

To see what your server's limit is:

SHOW VARIABLES LIKE 'max_allowed_packet';

If it shows something like 4194304, that's 4MB. Most SQL dumps with real data exceed this quickly.

Frequently Asked Questions

What is max_allowed_packet in MySQL?

It's the maximum size of a single SQL statement MySQL will accept. The default is usually 4MB or 16MB. Large INSERT statements in database dumps often exceed this.

How do I increase max_allowed_packet on shared hosting?

On shared hosting, you usually can't change MySQL settings. Your options are to re-export with smaller inserts or split the SQL file into smaller chunks.

Why does mysqldump create such large INSERT statements?

By default, mysqldump uses 'extended insert' which combines multiple rows into one INSERT for better performance. Use --skip-extended-insert for smaller statements.

Related articles

View all

Advertisement