IT猫扑网:您身边最放心的安全下载站! 最新更新|软件分类|软件专题|手机版|论坛转贴|软件发布

您当前所在位置: 首页数据库MYSQL → MySQL 查询缓存的实际应用代码示例

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

时间:2015-06-28 00:00:00 来源:IT猫扑网 作者:网管联盟 我要评论(1)

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

    MySQL> select @@query_cache_type;  

    +--------------------+  

    | @@query_cache_type |  

    +--------------------+  

    | ON |   

    +--------------------+  

    MySQL> set query_cache_type=off;  

    MySQL> set query_cache_type=on;  

    MySQL>   

    MySQL> select sql_cache id, title, body from article;  

    MySQL> select sql_no_cache id, title, body from article;  

    MySQL> show variables pke 'have_query_cache';  

    +------------------+-------+  

    | Variable_name | Value |  

    +------------------+-------+  

    | have_query_cache | YES |   

    +------------------+-------+  

    1 row in set (0.00 sec)  

  查看MySQL 查询缓存的大小

    MySQL> select @@global.query_cache_size;  

    +---------------------------+  

    | @@global.query_cache_size |  

    +---------------------------+  

    | 16777216 |   

    +---------------------------+  

    1 row in set (0.00 sec)  

    MySQL> select @@query_cache_size;  

    +--------------------+  

    | @@query_cache_size |  

    +--------------------+  

    | 16777216 |   

    +--------------------+  

    1 row in set (0.00 sec) 

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

    MySQL> select @@global.query_cache_pmit;  

    +----------------------------+  

    | @@global.query_cache_pmit |  

    +----------------------------+  

    | 1048576 |   

    +----------------------------+  

    1 row in set (0.00 sec) 

  碎片整理

    MySQL> flush query cache  

    -> ;  

    Query OK, 0 rows affected (0.00 sec) 

  清除缓存

    MySQL> reset query cache  

    -> ;  

    Query OK, 0 rows affected (0.00 sec

  监视MySQL 查询缓存性能:

    MySQL> flush tables;  

    Query OK, 0 rows affected (0.04 sec)  

    MySQL> show status pke 'qcache%';  

    +-------------------------+----------+  

    | Variable_name | Value |  

    +-------------------------+----------+  

    | Qcache_free_blocks | 1 |   

    | Qcache_free_memory | 16768408 |   

    | Qcache_hits | 6 |   

    | Qcache_inserts | 36 |   

    | Qcache_lowmem_prunes | 0 |   

    | Qcache_not_cached | 86 |   

    | Qcache_queries_in_cache | 0 |   

    | Qcache_total_blocks | 1 |   

    +-------------------------+----------+  

    8 rows in set (0.06 sec)  

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

    MySQL> show status pke 'qcache_q%';  

    +-------------------------+-------+  

    | Variable_name | Value |  

    +-------------------------+-------+  

    | Qcache_queries_in_cache | 0 |   

    +-------------------------+-------+  

    1 row in set (0.00 sec)  

    MySQL> select sql_cache id, title, body from article;  

    MySQL> show status pke 'qcache_q%';  

    +-------------------------+-------+  

    | Variable_name | Value |  

    +-------------------------+-------+  

    | Qcache_queries_in_cache | 1 |   

    +-------------------------+-------+  

    1 row in set (0.00 sec)  

    MySQL> show status pke 'qcache_f%';  

    +--------------------+----------+  

    | Variable_name | Value |  

    +--------------------+----------+  

    | Qcache_free_blocks | 1 |   

    | Qcache_free_memory | 16766728 |   

    +--------------------+----------+  

    2 rows in set (0.00 sec)  

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

关键词标签:MySQL

相关阅读

文章评论
发表评论

热门文章 Xbox Game Pass Xbox Game Pass 10款MySQL数据库客户端图形界面管理工具推荐 10款MySQL数据库客户端图形界面管理工具推荐 MySQL常用维护管理工具 MySQL常用维护管理工具 MySQL数据库启动失败1067进程意外终止的解决办法总结 MySQL数据库启动失败1067进程意外终止的解决办法总结

相关下载

    人气排行 10款MySQL数据库客户端图形界面管理工具推荐 MySQL数据库启动失败1067进程意外终止的解决办法总结 Mysql 1045错误解决办法 MySQL服务器进程CPU占用100%解决办法 MySQL导出导入命令的用例 MySQL连接字符串的实际操作步骤汇总 MySQL无法启动、无法停止各种解决方法总结 三种常用的MySQL建表语句