Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 286
kch Avatar asked Sep 18 '08 14:09

kch


People also ask

How to fix Got a packet bigger than max_ allowed_ packet bytes?

Temporarily increasing the packet size To do so, log into the MySQL service as a root user and run these commands: $ mysql -uroot mysql> SET GLOBAL net_buffer_length=1000000; mysql> SET GLOBAL max_allowed_packet=1000000000; This sets the max allowed packet to 1000000000, or 100MB.

What is max allowed packet size in MySQL?

The largest possible packet that can be transmitted to or from a MySQL 8.0 server or client is 1GB.

Where is max_allowed_packet in MySQL?

Open the "my. ini" file under the MySQL server install directory. Search for the "max_allowed_packet" parameter.

How do I fix the lost connection to MySQL server during query?

The error above commonly happens when you run a long or complex MySQL query that runs for more than a few seconds. To fix the error, you may need to change the timeout-related global settings in your MySQL database server.


4 Answers

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

like image 77
Michael Pryor Avatar answered Oct 07 '22 01:10

Michael Pryor


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

like image 24
Joshua Fox Avatar answered Oct 07 '22 01:10

Joshua Fox


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
like image 48
GHad Avatar answered Oct 07 '22 00:10

GHad


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

like image 18
kch Avatar answered Oct 07 '22 02:10

kch