MySQL max_allowed_packet setting

MySQL max_allowed_packet setting

max_allowed_packet is a parameter in MySQL that is used to set the size of the accepted packet. Depending on the situation, its default value may be 1M or 4M. For example, if it is 4M, the value is: 4 * 1024 * 1024 = 4194304

Phenomenon

When a message such as "Package for query is too large (xxxxxxxx > 4194304). You can change this value on the server by setting the max_allowed_package variable" appears in the log, the error itself clearly indicates the corresponding method.

Confirm max_allowed_package

Use the following method to confirm the current setting value

mysql> select @@max_allowed_packet;
+----------------------+
| @@max_allowed_packet |
+----------------------+
|4194304|
+----------------------+
1 row in set (0.00 sec)
mysql>

or

mysql> show variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+
1 row in set (0.00 sec)
mysql>

Revise

You can use the set command to modify it, but it is only a temporary modification and will be lost after restarting. You can also directly modify the MySQL configuration file and restart the MySQL service to permanently ensure the settings.

The modified files will be different depending on the installation of MySQL. The normal installation method may modify my.cnf. Here we use the official image of MySQL, and the modified file should be: /etc/mysql/mysql.conf.d/mysqld.cnf

Modification content: Add the following settings to this file
max_allowed_packet = 256M

Before modification

[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

After

[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_allowed_packet = 256M

Restart the container and confirm

mysql> show variables like '%max_allowed_pack%';
+--------------------------+------------+
| Variable_name | Value |
+--------------------------+------------+
| max_allowed_packet | 268435456 |
| slave_max_allowed_packet | 1073741824 |
+--------------------------+------------+
2 rows in set (0.01 sec)
mysql>

So we can see that it has been successfully set to 256M (268435456)

liumiaocn:~ liumiao$ echo "256*1024*1024" |bc
268435456
liumiaocn:~ liumiao$

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • How to configure the max_allowed_packet parameter in MySQL (to avoid failure in writing or updating large data)
  • How to modify the max_allowed_packet attribute of MySQL 5.5
  • How to modify the max_allowed_packet parameter of mysql database
  • Detailed explanation of max_allowed_packet parameter setting under MySQL

<<:  CentOS 7.x deployment of master and slave DNS servers

>>:  Detailed explanation of the new features of ES9: Async iteration

Recommend

HTML table layout example explanation

The elements in an HTML document are arranged one...

Difference between querySelector and getElementById methods in JS

Table of contents 1. Overview 1.1 Usage of queryS...

MYSQL performance analyzer EXPLAIN usage example analysis

This article uses an example to illustrate the us...

Specific use of GNU Parallel

what is it? GNU Parallel is a shell tool for exec...

Detailed explanation of the solution to the nginx panic problem

Regarding the nginx panic problem, we first need ...

The complete code of the uniapp packaged applet radar chart component

Effect picture: The implementation code is as fol...

Sample code for installing ElasticSearch and Kibana under Docker

1. Introduction Elasticsearch is very popular now...

How to implement on-demand import and global import in element-plus

Table of contents Import on demand: Global Import...

MySQL learning notes help document

View system help help contents mysql> help con...

How to implement encryption and decryption of sensitive data in MySQL database

Table of contents 1. Preparation 2. MySQL encrypt...