MySQL - Got a packet bigger than 'max_allowed_packet' bytes

By xngo on June 18, 2019

When you are importing a huge *.sql file into MySQL, it sometimes shows the following error message:

mysql -u root -p databasename < huge.sql
ERROR:...Got a packet bigger than 'max_allowed_packet' bytes ...

Simply open my.ini and increase max_allowed_packet and net_buffer_length variables.

max_allowed_packet = 10M
net_buffer_length = 2M


Update: 2010-08-17:

I got the freaking error mysqldump: Error 2020: Got packet bigger than 'max_allowed_packet' bytes when du' at line 1. Naturally, I edited my my.ini and increased the max_allowed_packet and net_buffer_length variables. But it didn't work. My *.sql file is 55 MB and I even increase max_allowed_packet up to 512 MB. But, it still returns the same error. I opened my *.sql file and found out that mysqldump generates only one INSERT command per table, resulting in one very long line of inserted data for each table that got dumped. So, I tried to re-export my database and this time, I requested mysqldump to export a separate INSERT query for every record in every table. I then imported it back and it worked. Here are the commands:

# Export a separate INSERT query for every record in every table
mysqldump --extended-insert=FALSE --complete-insert=TRUE -uUsername -p databasename > s.sql
 
# Import the database back.
mysql -uUsername -p databasename < s.sql

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.