MySQL Error 1153 - Got a packet bigger than 'max_allowed_packet' bytes

MysqlMax Allowed-Packet

Mysql Problem Overview


I'm importing a MySQL dump and getting the following error.

$ mysql foo < foo.sql 
ERROR 1153 (08S01) at line 96: Got a packet bigger than 'max_allowed_packet' bytes

Apparently there are attachments in the database, which makes for very large inserts.


This is on my local machine, a Mac with MySQL 5 installed from the MySQL package.

Where do I change max_allowed_packet to be able to import the dump?

Is there anything else I should set?

Just running mysql --max_allowed_packet=32M … resulted in the same error.

Mysql Solutions


Solution 1 - Mysql

You probably have to change it for both the client (you are running to do the import) AND the daemon mysqld that is running and accepting the import.

For the client, you can specify it on the command line:

mysql --max_allowed_packet=100M -u root -p database < dump.sql

Also, change the my.cnf or my.ini file (usually found in /etc/mysql/) under the mysqld section and set:

max_allowed_packet=100M

or you could run these commands in a MySQL console connected to that same server:

set global net_buffer_length=1000000; 
set global max_allowed_packet=1000000000;

(Use a very large value for the packet size.)

Solution 2 - Mysql

As michaelpryor said, you have to change it for both the client and the daemon mysqld server.

His solution for the client command-line is good, but the ini files don't always do the trick, depending on configuration.

So, open a terminal, type mysql to get a mysql prompt, and issue these commands:

set global net_buffer_length=1000000; 
set global max_allowed_packet=1000000000; 

Keep the mysql prompt open, and run your command-line SQL execution on a second terminal..

Solution 3 - Mysql

This can be changed in your my.ini file (on Windows, located in \Program Files\MySQL\MySQL Server) under the server section, for example:

[mysqld]

max_allowed_packet = 10M

Solution 4 - Mysql

Re my.cnf on Mac OS X when using MySQL from the mysql.com dmg package distribution

By default, my.cnf is nowhere to be found.

You need to copy one of /usr/local/mysql/support-files/my*.cnf to /etc/my.cnf and restart mysqld. (Which you can do in the MySQL preference pane if you installed it.)

Solution 5 - Mysql

The fix is to increase the MySQL daemon’s max_allowed_packet. You can do this to a running daemon by logging in as Super and running the following commands.

# mysql -u admin -p

mysql> set global net_buffer_length=1000000;
Query OK, 0 rows affected (0.00 sec)

mysql> set global max_allowed_packet=1000000000;
Query OK, 0 rows affected (0.00 sec)

Then to import your dump:

gunzip < dump.sql.gz | mysql -u admin -p database

Solution 6 - Mysql

In etc/my.cnf try changing the max_allowed _packet and net_buffer_length to

max_allowed_packet=100000000
net_buffer_length=1000000 

if this is not working then try changing to

max_allowed_packet=100M
net_buffer_length=100K 

Solution 7 - Mysql

On CENTOS 6 /etc/my.cnf , under [mysqld] section the correct syntax is:

[mysqld]
# added to avoid err "Got a packet bigger than 'max_allowed_packet' bytes"
#
net_buffer_length=1000000 
max_allowed_packet=1000000000
#

Solution 8 - Mysql

Use a max_allowed_packet variable issuing a command like

mysql --max_allowed_packet=32M -u root -p database < dump.sql

Solution 9 - Mysql

Slightly unrelated to your problem, so here's one for Google.

If you didn't mysqldump the SQL, it might be that your SQL is broken.

I just got this error by accidentally having an unclosed string literal in my code. Sloppy fingers happen.

That's a fantastic error message to get for a runaway string, thanks for that MySQL!

Solution 10 - Mysql

Error:

> ERROR 1153 (08S01) at line 6772: Got a packet bigger than > 'max_allowed_packet' bytes Operation failed with exitcode 1

QUERY:

SET GLOBAL max_allowed_packet=1073741824;
SHOW VARIABLES LIKE 'max_allowed_packet'; 

Max value:

Default Value (MySQL >= 8.0.3)	67108864
Default Value (MySQL <= 8.0.2)	4194304
Minimum Value	1024
Maximum Value	1073741824

Solution 11 - Mysql

Sometimes type setting:

max_allowed_packet = 16M

in my.ini is not working.

Try to determine the my.ini as follows:

set-variable = max_allowed_packet = 32M

or

set-variable = max_allowed_packet = 1000000000

Then restart the server:

/etc/init.d/mysql restart

Solution 12 - Mysql

It is a security risk to have max_allowed_packet at higher value, as an attacker can push bigger sized packets and crash the system.

So, Optimum Value of max_allowed_packet to be tuned and tested.

It is to better to change when required (using set global max_allowed_packet = xxx) than to have it as part of my.ini or my.conf.

Solution 13 - Mysql

I am working in a shared hosting environment and I have hosted a website based on Drupal. I cannot edit the my.ini file or my.conf file too.

So, I deleted all the tables which were related to Cache and hence I could resolve this issue. Still I am looking for a perfect solution / way to handle this problem.

Edit - Deleting the tables created problems for me, coz Drupal was expecting that these tables should be existing. So I emptied the contents of these tables which solved the problem.

Solution 14 - Mysql

I have resolved my issue by this query

SET GLOBAL max_allowed_packet=1073741824;

and check max_allowed_packet with this query

SHOW VARIABLES LIKE 'max_allowed_packet';

Solution 15 - Mysql

Set max_allowed_packet to the same (or more) than what it was when you dumped it with mysqldump. If you can't do that, make the dump again with a smaller value.

That is, assuming you dumped it with mysqldump. If you used some other tool, you're on your own.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkchView Question on Stackoverflow
Solution 1 - MysqlMichael PryorView Answer on Stackoverflow
Solution 2 - MysqlJoshua FoxView Answer on Stackoverflow
Solution 3 - MysqlGHadView Answer on Stackoverflow
Solution 4 - MysqlkchView Answer on Stackoverflow
Solution 5 - MysqlPrimoz RomeView Answer on Stackoverflow
Solution 6 - MysqlAmirtha RajanView Answer on Stackoverflow
Solution 7 - MysqlMike Castro DemariaView Answer on Stackoverflow
Solution 8 - MysqlTomasz TybulewiczView Answer on Stackoverflow
Solution 9 - MysqljplindstromView Answer on Stackoverflow
Solution 10 - MysqlTính Ngô QuangView Answer on Stackoverflow
Solution 11 - MysqlGrzegorz BrzęczyszczykiewiczView Answer on Stackoverflow
Solution 12 - MysqlShivaView Answer on Stackoverflow
Solution 13 - MysqlRaj Pawan GumdalView Answer on Stackoverflow
Solution 14 - MysqlAli Raza KhanView Answer on Stackoverflow
Solution 15 - MysqlMarkRView Answer on Stackoverflow