前置條件
設置參數
/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的值。