Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of max_allowed_packet setting in Mysql

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you the example analysis of max_allowed_packet settings in Mysql. I hope you will get something after reading this article. Let's discuss it together.

Max_allowed_packet is a setting parameter in Mysql, which is used to set the size of the accepted packet. Depending on the situation, the default value may be 1m or 4m. For example, in the case of 4m, the size of this value is: 4: 1024 * 1024 = 4194304

Phenomenon

When a prompt 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 way.

Confirm max_allowed_package

You can confirm the current setting value in the following ways

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 >

Modify

You can use the set command to modify it, but only temporarily and lose it after restart. You can also modify the mysql configuration file directly and restart the mysql service to make the guarantee settings permanent.

The modified file varies according to the installation of mysql. Ordinary installation may modify my.cnf. The official image of mysql is used here, and the modified file should be: / etc/mysql/mysql.conf.d/mysqld.cnf.

Modify: add the following settings to this file

Max_allowed_packet = 256m

Before modification

[mysqld] pid-file = / var/run/mysqld/mysqld.pidsocket = / var/run/mysqld/mysqld.sockdatadir = / var/lib/mysql#log-error = / var/log/mysql/error.log# By default we only accept connections from localhost#bind-address = 127.0.0.The Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0

After modification

[mysqld] pid-file = / var/run/mysqld/mysqld.pidsocket = / var/run/mysqld/mysqld.sockdatadir = / var/lib/mysql#log-error = / var/log/mysql/error.log# By default we only accept connections from localhost#bind-address = 127.0.0.The Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0max_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.01sec) mysql >

So we have seen that it has been successfully set to 256m (268435456).

Liumiaocn:~ liumiao$ echo "256-1024-1024" | bc268435456liumiaocn:~ liumiao$ has finished reading this article. I believe you have some understanding of "sample Analysis of max_allowed_packet Settings in Mysql". If you want to know more about it, please follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report