您的位置:首页 > 数据库 > SQL

MySQL的table_cache/table_open_cache参数

2014-04-21 17:03 330 查看


MySQL的table_cache/table_open_cache参数

调整这个参数要参考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的增加。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: