环境: Centos 7.2
程序: Mysql 5.6
操作:修改mysql的open_files_limit 配置
最近给新部署的mysql配置参数,需要修改open_files_limit配置,按照以往的经历,直接修改/etc/security/limits.conf 配置,在文件末尾添加如下内容:
root soft nofile 65535
root hard nofile 65535
mysql soft nofile 65535
mysql hard nofile 65535
* soft nofile 65535
* hard nofile 65535
重新登录后,查mysql进程的limits
cat /proc/mysql_process_id/limits
依然没有生效,说明修改limits.conf文件不生效。
然后查网上,直接修改my.cnf 文件,添加open_files_limit = 65535, 保存退出,重启mysqld服务,查限制,还是没有生效,于是查日志发现“[Warning] Buffered warning: Could not increase number of max_open_files to more than 1024 (request: 65535)” 。说明修改my.cnf文件不生效。
最后查官网,发现如果需要修改mysql的open_files_limit 配置,需要修改mysql的服务启动文件。修改如下:
mkdir /usr/lib/systemd/system/mysqld.service.d #创建子文件夹
vim /usr/lib/systemd/system/mysqld.service.d/limits.conf #创建并配置配置文件
[Service]
LimitNOFILE=10000
systemctl daemon-reload # 重新加载配置文件
systemctl restart mysqld.service #重启mysqld服务,使配置生效。
更改完后,再次检查limits限制,发现已经生效了,说明修改mysqld.server 配置是生效的。