mysql查看查询缓存是否启用

时间:2018-06-08 13:39:44   收藏:0   阅读:228
查看查询缓存情况:
mysql> show variables like ‘%query_cache%‘; 
(query_cache_type 为 ON 表示已经开启)
+------------------------------+----------+
| Variable_name                | Value    |
+------------------------------+----------+
| have_query_cache             | YES      |
| query_cache_limit            | 1048576  |
| query_cache_min_res_unit     | 4096     |
| query_cache_size             | 20971520 |
| query_cache_type             | ON       |
| query_cache_wlock_invalidate | OFF      |
+------------------------------+----------+
 
如果不是ON,修改配置文件以开启查询缓存:
> vi /etc/my.cnf
[mysqld]中添加:
query_cache_size = 20M
query_cache_type = ON
 
重启mysql服务:
> service mysql restart
 
查看缓存使用情况:
mysql> show status like ‘qcache%‘;  
+-------------------------+----------+
| Variable_name           | Value    |
+-------------------------+----------+
| Qcache_free_blocks      | 83       |
| Qcache_free_memory      | 19811040 |
| Qcache_hits             | 3108196  |
| Qcache_inserts          | 757254   |
| Qcache_lowmem_prunes    | 20720    |
| Qcache_not_cached       | 47219    |
| Qcache_queries_in_cache | 47       |
| Qcache_total_blocks     | 276      |
+-------------------------+----------+

    其中各个参数的意义如下:  

 

 

 

 

对于某些不想使用缓存的语句,可以这样使用:
select SQL_NO_CACHE count(*) from users where email = ‘hello‘;

原文:https://www.cnblogs.com/penghq/p/9154729.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!