You get a bonus - 1 coin for daily activity. Now you have 1 coin

MySQL: how to change the maximum query length, or the "ERROR 1153 (08S01) at line 1: Got a packet bigger than 'max_allowed_packet' bytes" error

Practice



If you get an error like this in response to a query:

ERROR 1153 (08S01) at line 1: Got a packet bigger than 'max_allowed_packet' bytes

then it's obvious that the query you built (or the software that's talking to MySQL) is too long to be processed.

There are two ways to fix this:
  • If you wrote the software yourself (say, it's a website or just your own program) - optimize the query so it fits within the standard 65535-character length.
  • If you can't change the query length - then change the max_allowed_packet variable in the configuration file.


Checking the current value

You can check the value of max_allowed_packet with a query right in MySQL itself:

mysql> SHOW VARIABLES LIKE 'max_allowed_packet';


Changing the max_allowed_packet value

To do this, open the my.cnf file for editing.

Now, in the [mysqld] section, add (or change, if it's already there) the line:
max_allowed_packet = 32M
where instead of 32M - substitute whatever value you need.

The default is usually 16M (16*1024*1024).


After making the change - restart the MySQL service.

for Debian/ubuntu:
$ sudo /etc/init.d/mysql restart

for CentOS/RedHat:
$ sudo /etc/init.d/mysqld restart

for FreeBSD:
$ sudo /usr/local/etc/rc.d/mysql-server restart

Comments

Админ 22-06-2020
/etc/mysql/my.cnf
Илья 21-06-2020
напишите полный путь к my.cnf

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Databases - MySql (Maria DB)"

Terms: Databases - MySql (Maria DB)