mysql> SHOW GLOBAL STATUS LIKE 'open%tables%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Open_tables | 919 |
| Opened_tables | 1951 |
+---------------+-------+
-- 快取命中率
Open_tables / Opened_tables * 100% -- 建議 >= 85%
-- 快取使用率
Open_tables / table_open_cache * 100% -- 建議 70%~90%
mysql> SHOW VARIABLES LIKE 'table_open_cache';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| table_open_cache | 2048 |
+------------------+-------+
MySQL 5.1.3 前參數名為 `table_cache`,之後統一為 `table_open_cache`。
| 現象 | 原因 | 對策 |
|---|---|---|
| Opened_tables 快速增長 | table_open_cache 過小,頻繁開啟/關閉表 | 調大 table_open_cache (如 2048→4096) |
| Open_tables 接近上限 | 快取池滿,新表需淘汰舊表 | 調大上限,或檢查是否有大量臨時表 |
| 命中率 < 85% | 快取不足或表存取模式極度分散 | 調大快取、合併低頻表、拆分熱點表 |
`table_open_cache` 實際上限受限於 `open_files_limit`(每表約需 2~3 個檔案描述符:.frm, .MYD, .MYI 或 .ibd)。調大前請確認 `ulimit -n` 與 `open_files_limit` 足夠。