Open_tables Opened_tables table_open_cache

今天开发说应用链接数据库比较慢,定位后发现是table_open_cache太小了引起的问题。

如果你发现Opened_tables比较大并且一直再增大,很可能是table_open_cache设置太小了,导致每次链接数据库都要去打开表,这也会造成链接数据库比较慢。

Open_tables : The number of tables that are open.

Opened_tables : The number of tables that have been opened. If Opened_tables is big, your table_open_cache value is probably too small.

table_open_cache :The number of open tables for all threads. Increasing this value increases the number of file descriptors 
that mysqld requires. You can check whether you need to increase the table cache by checking the Opened_tables status variable. 
If the value of Opened_tables is large and you do not use FLUSH TABLES often (which just forces all tables to be closed and 
reopened), then you should increase the value of the table_open_cache variable. For more information about the table cache,

测试:

mysql> show variables like 'table_open_cache';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| table_open_cache | 4     |
+------------------+-------+
1 row in set (0.00 sec)

mysql>  show global status like 'open%tables%'; 
+---------------+----------+
| Variable_name | Value    |
+---------------+----------+
| Open_tables   | 4        |
| Opened_tables | 11412131 |
+---------------+----------+
2 rows in set (0.00 sec)
mysql> exit



[root@slave159 bin]# mysql -uroot -h192.168.60.204 -p1234 pva1
-- 说明:3s左右才登陆
mysql>  show global status like 'open%tables%'; 
+---------------+----------+
| Variable_name | Value    |
+---------------+----------+
| Open_tables   | 4        |
| Opened_tables | 11413673 |
+---------------+----------+
2 rows in set (0.01 sec)

mysql> select 11413673-11412131;
+-------------------+
| 11413673-11412131 |
+-------------------+
|              1542 |
+-------------------+
1 row in set (0.00 sec)


mysql> set global table_open_cache=2000;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye

[root@slave159 bin]# mysql -uroot -h192.168.60.204 -p1234 pva1
-- 说明:3s左右才登陆
mysql> show global status like 'open%tables%'; 
+---------------+----------+
| Variable_name | Value    |
+---------------+----------+
| Open_tables   | 574      |
| Opened_tables | 11433986 |
+---------------+----------+
mysql> exit
Bye

[root@slave159 bin]# mysql -uroot -h192.168.60.204 -p1234 pva1
-- 说明:1s内就登陆了
mysql> show global status like 'open%tables%'; 
+---------------+----------+
| Variable_name | Value    |
+---------------+----------+
| Open_tables   | 574      |
| Opened_tables | 11433986 |
+---------------+----------+


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值