MySQL Got a packet bigger than ‘max_allowed_packet’ bytes

We were doing a big database import in MySQL and we got this error message during the process.

Got a packet bigger than ‘max_allowed_packet’ bytes.

Here are the changes we needed to make it work. We are running on CentOS.

1. Edit /etc/my.cnf and add the following lines. The packet value we want for this example is 500M.

[mysqld]
max_allowed_packet=500M

2. Restart MySQL.

> service mysqld restart

3. Run the MySQL import process with the max_allowed_packet parameter. Replace USERNAME, DATABASE and DUMP with the appropriate values.

> mysql --max_allowed_packet=500M -u USERNAME -p DATABASE < DUMP.sql

Wait for the import process to complete and that should be it.