在线应用linux +mysqlshow variables like '%query_cache%';
+------------------------------+---------+
| Variable_name                | Value   |
+------------------------------+---------+
| have_query_cache             | YES     |
| query_cache_limit            | 1048576 |
| query_cache_min_res_unit     | 4096    |
| query_cache_size             | 0       |--------------表明缓存区大小为0
| query_cache_type             | OFF     |--------------表明缓存关闭
| query_cache_wlock_invalidate | OFF     |
+------------------------------+---------+
6 rows in set请问我在my.cnf如何才能配置打开 缓存??

解决方案 »

  1.   

    找到应该 是 #result set and query cache
    query_cache_type = 0
    query_cache_size = 0show status like '%Qcache%';
    +-------------------------+-------+
    | Variable_name           | Value |
    +-------------------------+-------+
    | Qcache_free_blocks      | 0     |
    | Qcache_free_memory      | 0     |
    | Qcache_hits             | 0     |
    | Qcache_inserts          | 0     |
    | Qcache_lowmem_prunes    | 0     |
    | Qcache_not_cached       | 0     |
    | Qcache_queries_in_cache | 0     |
    | Qcache_total_blocks     | 0     |
    +-------------------------+-------+
    8 rows in set
      

  2.   

    从实现原理来看,query cache确实以比较简单实现带来巨大性能收益。但是他有很多负面影响
    1query语句的hash运算以及hash查找资源消耗。对于每秒上千或者几千条query的高并发环境,不能他差生的cpu消耗完全忽略。 (每条sql都要到query cache里看是否存在)
    2 query cache失效问题。 如果哦b表变化过于频繁,按么造成他的失效率非常高。这里表不仅表示表中数据的变更,而且表结构和索引等变化都包含。
    3 他缓存的是result set。不是数据页。也就是说, 同一条记录被cache多次的可能性,从而造成内存资源的浪费。所以基本没有什么用。
      

  3.   

    你可以自己定义那些需要缓存,那些不需要;quear_cache_type=2可以避免你第2个问题.以及limit 的限制.