最新消息:觉得本站不错的话 记得收藏哦 博客内某些功能仅供测试 讨论群:135931704 快养不起小站了 各位有闲钱就打赏下把 My Email weicots#gmail.com Please replace # with @

MySQL Error 1153 – Got a packet bigger than ‘max_allowed_packet’ bytes

LINX-SQL ajiang-tuzi 64510浏览
Stack Overflow is a question and answer site for professional and enthusiast programmers. It’s 100% free.

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.

shareimprove this question
4
This blog is worth reading for ‘max_allowed_packet’ error: webyog.com/blog/2009/08/10/… –? Ashwin A Aug 21 ’12 at 9:24
possible duplicate of How to change max_allowed_packet size –? Muleskinner Jan 17 ’14 at 14:19

11 Answers

up vote317down voteaccepted

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

shareimprove this answer
8
guess corporate support still beats this community thing 😛 –? kch Sep 19 ’08 at 20:23
I have a server with 16 GB of RAM, is it a bad idea to set max_allowed_packet to 100 MB? –? WebnetNov 8 ’10 at 14:53
@webnet its probably fine. –? Michael Pryor Nov 9 ’10 at 17:36
5
FYI – it helped me to solve a DIFFERENT error – “#2006 server has gone away” –? itsho Dec 13 ’11 at 16:05
11
Be aware that using “set global” works until the next mysql service restart. –? Will Shaver Nov 16 ’12 at 21:28

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

shareimprove this answer
2
Solved the problem for me; the import I’m doing is a once-off, and I can’t easily change the configuration. This worked great. 😀 –? Rob Howard Nov 26 ’09 at 4:11
Perfect solution – needed it only for 1-time import! –? Leonti Aug 9 ’10 at 20:14
This was the only solution that worked for me as well. –? PETER BROWN Nov 4 ’11 at 16:16
Thanks a lot for this answer, it saved my day! –? Denis Fuenzalida Apr 17 ’13 at 0:42
Thanks a lot..Its working fine.. –? Abhi Mar 28 ’14 at 10:37

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
shareimprove this answer
4
on a mac, file obviously located elsewhere. –? kch Sep 18 ’08 at 14:44
2
sure, but the configuration is still somewhere although I don’t know the exact location –? GHad Sep 18 ’08 at 17:15
For me in Fedora 20 with MariaDB, placing that setting at the end of /etc/my.cnf.d/server.cnf did the trick. I had to restart the service of course… sudo nano systemctl restart mariadb.service –? Ray Aug 11 ’14 at 19:54

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

shareimprove this answer
The default config in place for OSX appears to be my-medium.cnf, although the max_allowed_packet size is the same in my-large.cnf … until you start changing things :) –? Chris Burgess Aug 1 ’11 at 0:15

Use a max_allowed_packet variable issuing a command like

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

shareimprove this answer
1
tried that, didn’t work. whole dump in 272mb, tried with max higher than that. –? kch Sep 18 ’08 at 14:46

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!

shareimprove this answer

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
#
shareimprove this answer

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
shareimprove this answer

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 
shareimprove this answer

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.

shareimprove this answer
did that, didn’t work. used mysqldump indeed. –? kch Sep 18 ’08 at 19:16

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.

shareimprove this answer

protected by Community? Jan 8 ’12 at 20:13

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you’re looking for? Browse other questions tagged or ask your own question.

转载请注明:(●--●) Hello.My Weicot » MySQL Error 1153 – Got a packet bigger than ‘max_allowed_packet’ bytes

蜀ICP备15020253号-1