mysql "Too many open files”问题解决

来源:互联网 发布:js文字大小变化效果 编辑:程序博客网 时间:2024/05/09 05:38

背景介绍

最近在mysql服务器上运行了一个爬虫程序,其他用户访问mysql(5.7)数据库的时候老是报错“Too many openf files”,现在把解决问题的方案记录下来。

首先我查看mysql open_files_limit参数

mysql> show variables like '%open_files_limit%';

然后查看mysql官网关于open_files_limit参数说明,大体上是说该参数决定了mysql进程能打开的最大文件数。这个最大文件数依赖于操作系统,如果进程需要打开的文件数无法被分配成功的时候就会报出错误或警告。
在Unix系统中open_file_limit不会超过操作系统ulimit -n所指定的文件数。
mysql实例启动时,取下面三个值中最大值为open_files_limit参数值

1) 10 + max_connections + (table_open_cache * 2)2) max_connections * 53) open_files_limit value specified at startup, 5000 if none

修改操作系统打开文件限制

查看

ulimit -n1024

修改/etc/security/limits.conf

mysql soft nofile  102400mysql hard nofile  102400

修改mysql最大打开文件数限制

修改/etc/my.cnf 加入:

open_files_limit=102400
原创粉丝点击