MySQL缓存命中率,网上说法不一,下面我说下我的看法,大家轻拍:
总的select查询数等于com_select(没命中) + qcache_hits(命中) + 解析错误的查询。
再来看看Com_select变量:
mysql> show global status like 'Com_select';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_select | 46 |
+---------------+-------+
com_select等于qcache_inserts(缓存失效) + qcache_not_cache(没有缓存) + 权限检查错误的查询。
因此,Mysql的查询缓存命中率 ≈ qcache_hits / (qcache_hits + com_select)
查询缓存变量:
mysql> show global status like 'QCache%'
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 18856920 |
| Qcache_hits | 3 |
| Qcache_inserts | 20 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 26 |
| Qcache_queries_in_cache | 0 |
| Qcache_total_blocks | 1 |
+-------------------------+----------+
因此本例中的查询缓存命中率 ≈ 3/(3+46) = 6.12%
查询缓存变量含义: