返回列表 发帖

MySQL的最大连接数/最大可打开表数/最大可打开文件数

笺注:MySQL的安装可参考 Apache2.2+MySQL5.6+PHP5.6+phpMyAdmin+GLPI


查看MySQL的版本信息:
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.42    |
+-----------+
1 row in set (0.00 sec)


查看MySQL的最大连接数:
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+
1 row in set (0.10 sec)


查看MySQL当前打开的连接数:
mysql> show status like 'threads_connected';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 1     |
+-------------------+-------+
1 row in set (0.00 sec)


查看MySQL当前处于激活状态的连接数:
mysql> show status like 'threads_running';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| Threads_running | 1     |
+-----------------+-------+
1 row in set (0.00 sec)



查看MySQL的“最大可打开表数”:(能同时打开的表的总数量)
mysql> show variables like 'table_open%';
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| table_open_cache           | 2000 |
| table_open_cache_instances | 1     |
+----------------------------+-------+
2 rows in set (0.00 sec)


查看MySQL当前打开的表的数量:
mysql> show status like 'open_table%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| Open_table_definitions | 67    |
| Open_tables            | 60    |
+------------------------+-------+
2 rows in set (0.00 sec)

笺注:假如Open_tables的值比较大,或等于table_open_cache的值,就可以把table_open_cache的值调大一些。



查看MySQL的“最大可打开文件数”:
mysql> show global variables like '%open_files_limit%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| open_files_limit | 5000  |
+------------------+-------+
1 row in set (0.00 sec)





修改MySQL的主配置文件:
[root@localhost ~]# vi /etc/my.cnf
#在[mysqld]下面插入:
table_open_cache = 3000  #修改MySQL能同时打开的表的总数量
max_connections = 10008  #修改MySQL的最大连接数
max_connect_errors = 100  #每个客户端的连接失败的最大允许次数
open_files_limit = 65535  #修改MySQL的最大可打开文件数


[root@localhost ~]# service mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]


再次查看MySQL的最大连接数:(服务器重启后依旧生效)
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 10008 |
+-----------------+-------+
1 row in set (0.00 sec)


再次查看MySQL的“最大可打开表数”:(服务器重启后依旧生效)
mysql> show variables like 'table_open%';
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| table_open_cache           | 3000  |
| table_open_cache_instances | 1     |
+----------------------------+-------+
2 rows in set (0.00 sec)


再次查看MySQL当前打开的表的数量:
mysql> show status like 'open_table%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| Open_table_definitions | 67    |
| Open_tables            | 60    |
+------------------------+-------+
2 rows in set (0.00 sec)


再次查看MySQL的最大可打开文件数:(服务器重启后依旧生效)
mysql> show global variables like '%open_files_limit%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| open_files_limit | 65535 |
+------------------+-------+
1 row in set (0.01 sec)


测试MySQL的最大可打开文件数:
[root@localhost ~]# ps -ef |grep mysql |grep -v grep
root       1417      1  0 05:36 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql      1660   1417  3 05:36 ?        00:00:09 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --open-files-limit=65535 --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock

cat /proc/1417/limits
图片1.png



操作系统的“进程最大可打开文件数”的查询方法:
[root@localhost ~]# ulimit -n
1024


操作系统的“进程最大可打开文件数”的修改方法:
[root@localhost ~]# tail -5 /etc/security/limits.conf
# End of file
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535



重启服务器:
[root@localhost ~]# reboot


服务器重启后,更改生效:
[root@localhost ~]# ulimit -n
65535





相关文章:
使用SQLyog远程管理MySQL
CentOS8使用Python3脚本管理MySQL8.0

Zabbix自定义监控Linux下的MySQL
Zabbix调用Python3脚本监控Linux下的MySQL

MariaDB的最大连接数/最大可打开表数/最大可打开文件数

返回列表