这篇文章给大家介绍如何进行MySQL查询缓存的实际应用代码分析,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

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

MySQL>select@@query_cache_type;

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

|@@query_cache_type|

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

|ON|

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

MySQL>setquery_cache_type=off;

MySQL>setquery_cache_type=on; 100.Com

MySQL>

MySQL>selectsql_cacheid,title,bodyfromarticle;

MySQL>selectsql_no_cacheid,title,bodyfromarticle;

MySQL>showvariableslikehave_query_cache;

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

|Variable_name|Value|

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

|have_query_cache|YES|

+------------------+-------+ phP100.Com

1rowinset(0.00sec)

查看MySQL 查询缓存的大小

MySQL>select@@global.query_cache_size;

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

|@@global.query_cache_size|

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

|16777216|

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

1rowinset(0.00sec)

MySQL>select@@query_cache_size;

+--------------------+ phP100.Com

|@@query_cache_size|

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

|16777216|

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

1rowinset(0.00sec)

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

MySQL>select@@global.query_cache_limit;

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

|@@global.query_cache_limit|

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

|1048576|

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

1rowinset(0.00sec)

  碎片整理

MySQL>flushquerycache

->;

QueryOK,0rowsaffected(0.00sec)

  清除缓存

MySQL>resetquerycache phP100.Com

->;

QueryOK,0rowsaffected(0.00sec

监视MySQL 查询缓存性能:

MySQL>flushtables;

QueryOK,0rowsaffected(0.04sec)

MySQL>showstatuslikeqcache%;

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

|Variable_name|Value|

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

|Qcache_free_blocks|1|

|Qcache_free_memory|16768408|

|Qcache_hits|6|

|Qcache_inserts|36| PhP100.Com

|Qcache_lowmem_prunes|0|

|Qcache_not_cached|86|

|Qcache_queries_in_cache|0|

|Qcache_total_blocks|1|

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

8rowsinset(0.06sec)

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

MySQL>showstatuslikeqcache_q%;

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

|Variable_name|Value|

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

|Qcache_queries_in_cache|0|

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

1rowinset(0.00sec)

关于如何进行MySQL查询缓存的实际应用代码分析就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。