mysql查询缓存命中总是0
mysql> show variables like '%query_cache%';+------------------------------+----------+
| Variable_name | Value |
+------------------------------+----------+
| have_query_cache | YES |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 16777216 |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
+------------------------------+----------+
mysql> select count(*) from user;
+----------+
| count(*) |
+----------+
| 17 |
+----------+0条命中
mysql> show status like 'Qcache_hits';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Qcache_hits | 0 |
+---------------+-------+//没有被缓存的查询反而增加
mysql> show status like 'Qcache_not_cached';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Qcache_not_cached | 166 |
+-------------------+-------+
mysql> show variables like '%query_cache%';+------------------------------+----------+
| Variable_name | Value |
+------------------------------+----------+
| have_query_cache | YES |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 16777216 |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
+------------------------------+----------+
mysql> select count(*) from user;
+----------+
| count(*) |
+----------+
| 17 |
+----------+0条命中
mysql> show status like 'Qcache_hits';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Qcache_hits | 0 |
+---------------+-------+//没有被缓存的查询反而增加
mysql> show status like 'Qcache_not_cached';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Qcache_not_cached | 166 |
+-------------------+-------+
先看看原理http://wenku.baidu.com/view/f6f5f9bb1a37f111f1855b99.html
query_cache_type 在MyISAM下可以开,设置有效 在Innodb引擎下无效