MySQL 查询缓存的实际应用代码示例

数据库 MySQL
此文章主要是向大家描述的是MySQL 查询缓存的实际应用代码以及查看MySQL 查询缓存的大小,与监视MySQL 查询缓存性能的内容描述。

以下的文章主要介绍的是MySQL 查询缓存的实际应用代码以及查看MySQL 查询缓存的大小 ,碎片整理,清除缓存以及监视MySQL 查询缓存性能的相关内容的描述,以下就是具体内容的描述,希望在你今后的学习中会有所帮助。

  1. MySQL> select @@query_cache_type;  
  2. +--------------------+  
  3. | @@query_cache_type |  
  4. +--------------------+  
  5. | ON |   
  6. +--------------------+  
  7. MySQL> set query_cache_type=off;  
  8. MySQL> set query_cache_type=on;  
  9. MySQL>   
  10. MySQL> select sql_cache id, title, body from article;  
  11. MySQL> select sql_no_cache id, title, body from article;  
  12. MySQL> show variables like 'have_query_cache';  
  13. +------------------+-------+  
  14. | Variable_name | Value |  
  15. +------------------+-------+  
  16. | have_query_cache | YES |   
  17. +------------------+-------+  
  18. 1 row in set (0.00 sec)  

 

查看MySQL 查询缓存的大小

 

  1. MySQL> select @@global.query_cache_size;  
  2. +---------------------------+  
  3. | @@global.query_cache_size |  
  4. +---------------------------+  
  5. | 16777216 |   
  6. +---------------------------+  
  7. 1 row in set (0.00 sec)  
  8. MySQL> select @@query_cache_size;  
  9. +--------------------+  
  10. | @@query_cache_size |  
  11. +--------------------+  
  12. | 16777216 |   
  13. +--------------------+  
  14. 1 row in set (0.00 sec)   

 

查看***缓存结果,如果结果集大于该数,不缓存。

 

  1. MySQL> select @@global.query_cache_limit;  
  2. +----------------------------+  
  3. | @@global.query_cache_limit |  
  4. +----------------------------+  
  5. | 1048576 |   
  6. +----------------------------+  
  7. 1 row in set (0.00 sec) 

 

 

碎片整理

 

  1. MySQL> flush query cache  
  2. -> ;  
  3. Query OK, 0 rows affected (0.00 sec)  

 

清除缓存

  1. MySQL> reset query cache  
  2. -> ;  
  3. Query OK, 0 rows affected (0.00 sec) 

 

监视MySQL 查询缓存性能:

 

  1. MySQL> flush tables;  
  2. Query OK, 0 rows affected (0.04 sec)  
  3. MySQL> show status like 'qcache%';  
  4. +-------------------------+----------+  
  5. | Variable_name | Value |  
  6. +-------------------------+----------+  
  7. | Qcache_free_blocks | 1 |   
  8. | Qcache_free_memory | 16768408 |   
  9. | Qcache_hits | 6 |   
  10. | Qcache_inserts | 36 |   
  11. | Qcache_lowmem_prunes | 0 |   
  12. | Qcache_not_cached | 86 |   
  13. | Qcache_queries_in_cache | 0 |   
  14. | Qcache_total_blocks | 1 |   
  15. +-------------------------+----------+  
  16. 8 rows in set (0.06 sec)  

 

看看当前缓存中有多少条信息:

 

  1. MySQL> show status like 'qcache_q%';  
  2. +-------------------------+-------+  
  3. | Variable_name | Value |  
  4. +-------------------------+-------+  
  5. | Qcache_queries_in_cache | 0 |   
  6. +-------------------------+-------+  
  7. 1 row in set (0.00 sec)  
  8. MySQL> select sql_cache id, title, body from article;  
  9. MySQL> show status like 'qcache_q%';  
  10. +-------------------------+-------+  
  11. | Variable_name | Value |  
  12. +-------------------------+-------+  
  13. | Qcache_queries_in_cache | 1 |   
  14. +-------------------------+-------+  
  15. 1 row in set (0.00 sec)  
  16. MySQL> show status like 'qcache_f%';  
  17. +--------------------+----------+  
  18. | Variable_name | Value |  
  19. +--------------------+----------+  
  20. | Qcache_free_blocks | 1 |   
  21. | Qcache_free_memory | 16766728 |   
  22. +--------------------+----------+  
  23. 2 rows in set (0.00 sec)  

 

 

以上的相关内容就是对MySQL 查询缓存的介绍,望你能有所收获。

【编辑推荐】

  1. 安装MySQL-python的实际操作步骤
  2. MySQL 常用语句的基本用法的介绍
  3. 解决MySQL无法远程访问的3方案
  4. PHP和MySQL存储过程的实例演示
  5. MySQL delimiter 定义命令的结束标志
责任编辑:佚名 来源: cnblogs
相关推荐

2010-06-02 13:33:19

MySQL 查询缓存

2010-05-19 12:44:58

2010-05-18 16:29:44

MySQL修改表

2010-05-17 09:25:34

MySql 编码设置

2010-04-21 13:31:11

Oracle时间

2010-04-12 12:30:44

Oracle 安装脚本

2010-04-12 09:26:52

Oracle查询分页

2010-04-13 14:25:24

Oracle问题解决

2010-03-23 13:30:36

Python VIM

2010-05-31 14:59:36

PHP + MySQL

2010-05-18 17:24:44

MySQL修改表字段

2010-04-19 11:37:20

Oracle数据库

2010-05-12 09:42:24

MySQL 列值比较

2021-07-19 15:12:21

Python编程语言

2010-05-25 18:21:28

MySQL连接数据库

2010-05-04 15:15:39

Oracle分页查询

2024-01-23 09:57:50

MySQL数据库

2017-05-01 17:03:01

Java缓存分布式

2010-06-02 17:31:10

MySQL定时任务

2010-05-24 09:57:08

点赞
收藏

51CTO技术栈公众号