Home > Database > Mysql Tutorial > body text

mysql中max_allowed_packet参数的配置方法(避免大数据写入或者_MySQL

WBOY
Release: 2016-06-01 13:13:17
Original
945 people have browsed it

MySQL根据配置文件会限制Server接受的数据包大小。有时候大的插入和更新会受 max_allowed_packet 参数限制,导致写入或者更新失败。

查看目前配置:
show VARIABLES like '%max_allowed_packet%';
显示的结果为:
+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+ 
以上说明目前的配置是:1M

修改方法

1、修改配置文件

可以编辑my.cnf来修改(windows下my.ini),在[mysqld]段或者mysql的server配置段进行修改。
max_allowed_packet = 20M
如果找不到my.cnf可以通过
mysql --help | grep my.cnf
去寻找my.cnf文件。
linux下该文件在/etc/下。

2、在mysql命令行中修改

在mysql 命令行中运行:
set global max_allowed_packet = 2*1024*1024*10
然后退出命令行,重启mysql服务,再进入。
show VARIABLES like '%max_allowed_packet%';
查看下max_allowed_packet是否编辑成功

注意:该值设置过小将导致单个记录超过限制后写入数据库失败,且后续记录写入也将失败。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!