我们致力于一个MySQL知识的分享网站

  |   本站Feed      

MySQL的table_cache参数

2009-08-04 23:00:02  |   才被阅读:874 次  |   要评论?
分类: MySQL基础知识  |   发布: OurMySQL  |   来源:stronghearted life
标签:

Mysql对table_cache解释

mysql> system mysqld –verbose –help|grep
max_connections + table_cache*2 (whichever is larger)
–table_cache=# The number of open tables for all threads.
table_cache 64

调整这个参数要参考open_tables及opened_tables

Open_tables:当前打开表的缓存数
Opened_tables:曾经打开表的缓存数,会一直累加。

mysql> show variables like ‘table_cache%’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| table_cache | 64 |
+—————+——-+
1 row in set (0.01 sec)

mysql> show global status like ‘open%table%’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| Open_tables | 30 |
| Opened_tables | 136 |
+—————+——-+
2 rows in set (0.00 sec)

执行flush tables后,open_tables会清0,opened_tables则不会。因为flush_tables后,mysql会关闭打开的缓存表。

mysql> flush tables;
Query OK, 0 rows affected (0.01 sec)
mysql> show global status like ‘open%table%’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| Open_tables | 0 |
| Opened_tables | 136 |
+—————+——-+
2 rows in set (0.00 sec)

这里查询张表t1

mysql> select count(*) from t1;
+———-+
| count(*) |
+———-+
| 0 |
+———-+
1 row in set (0.00 sec)

mysql> show global status like ‘open%table%’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| Open_tables | 1 | —增加了1
| Opened_tables | 137 | —增加了1
+—————+——-+
2 rows in set (0.00 sec)

再执行一次

mysql> select count(*) from t1;
+———-+
| count(*) |
+———-+
| 0 |
+———-+
1 row in set (0.00 sec)

mysql> show global status like ‘open%table%’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| Open_tables | 1 | —没有加1
| Opened_tables | 137 | —没有加1
+—————+——-+
2 rows in set (0.00 sec)

因为t1已经打开过一次了。

BTW:如果opened_tables每秒中打开的比较多,一般情况下,说明table_cahce太小了,但也存在另外一种情况:table cahce没有全部使用,临时表的打开,也会导致opened_tables的增加。

相关文章

  • 目前没有相关的文章

Leave a Reply