前置条件
设置参数
/etc/security/limits.conf中设置如下
* soft nofile 100001
* hard nofile 100002
root soft nofile 100001
root hard nofile 100002
mysql soft nofile 65535
mysql hard nofile 65535
my.cnf中设置如下
table_open_cache=5000
open_files_limit=20000
innodb_open_files=10000
open_files_limit 取值标准
mysql用户重启服务
重启mysql,以mysql用户启动服务
/bin/sh /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my8.cnf --user=mysql &
查询参数值
mysql> show variables like '%open%';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| have_openssl | YES |
| innodb_open_files | 10000 |
| mysqlx_port_open_timeout | 0 |
| open_files_limit | 65535 |
| table_open_cache | 5000 |
| table_open_cache_instances | 16 |
+----------------------------+-------+
innodb_open_files 10000 和配置文件中一致
open_files_limit 65535 和操作系统mysql用户文件句柄数一致
table_open_cache 5000 和配置文件中一致
root用户重启服务
重启mysql,以root用户启动服务
查看参数值
mysql> show variables like '%open%';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| have_openssl | YES |
| innodb_open_files | 10000 |
| mysqlx_port_open_timeout | 0 |
| open_files_limit | 20000 |
| table_open_cache | 5000 |
| table_open_cache_instances | 16 |
+----------------------------+-------+
innodb_open_files 10000 和配置文件中一致
open_files_limit 20000 和配置文件中一致
table_open_cache 5000 和配置文件中一致
innodb_open_files取值标准
修改innodb_open_files的值
table_open_cache=5000
open_files_limit=20000
innodb_open_files=30000
使用mysql用户启动
mysql> show variables like '%open%';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| have_openssl | YES |
| innodb_open_files | 30000 |
| mysqlx_port_open_timeout | 0 |
| open_files_limit | 65535 |
| table_open_cache | 5000 |
| table_open_cache_instances | 16 |
+----------------------------+-------+
innodb_open_files 读取配置文件的值
使用root用户启动
mysql> show variables like '%open%';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| have_openssl | YES |
| innodb_open_files | 5000 |
| mysqlx_port_open_timeout | 0 |
| open_files_limit | 20000 |
| table_open_cache | 5000 |
| table_open_cache_instances | 16 |
+----------------------------+-------+
如果它大于 open_files_limit 且大于 table_open_cache 则取值table_open_cache
总结
1、innodb_open_files 和open_files_limit 两个参数值生效,和操作系统配置和配置文件配置有关系,且和不同操作系统启动服务也有关。
2、open_files_limit : 如果是root账号启动 以my.cnf文件里面的值为准, 如果是mysql启动, 就可能是 ulimit -n 看到的那个值
3、innodb_open_files :如果以mysql账户启动,则取my.cnf文件里面的值为准;
如果用root账户启动, 如果它大于 open_files_limit 且大于 table_open_cache 则取值table_open_cache,否则取配置文件my.cnf的值。