<p>MySQL 查询缓存的实际应用代码示例<br /> 以下的文章主要介绍的是MySQL 查询缓存的实际应用代码以及查看MySQL 查询缓存的大小 ,碎片整理,清除缓存以及监视MySQL 查询缓存性能的相关内容的描述,以下就是具体内容的描述,希望在你今后的学习中会有所帮助。<br /> <br /> MySQL&gt; select @@query_cache_type;<br /> +--------------------+<br /> | @@query_cache_type |<br /> +--------------------+<br /> | ON |<br /> +--------------------+<br /> MySQL&gt; set query_cache_type=off;<br /> MySQL&gt; set query_cache_type=on; php100.Com<br /> MySQL&gt;<br /> MySQL&gt; select sql_cache id, title, body from article;<br /> MySQL&gt; select sql_no_cache id, title, body from article;<br /> MySQL&gt; show variables like &#39;have_query_cache&#39;;<br /> +------------------+-------+<br /> | Variable_name | Value |<br /> +------------------+-------+<br /> | have_query_cache | YES |<br /> +------------------+-------+ phP100.Com<br /> 1 row in set (0.00 sec)<br />   查看MySQL 查询缓存的大小<br /> <br /> MySQL&gt; select @@global.query_cache_size;<br /> +---------------------------+<br /> | @@global.query_cache_size |<br /> +---------------------------+<br /> | 16777216 |<br /> +---------------------------+<br /> 1 row in set (0.00 sec)<br /> MySQL&gt; select @@query_cache_size;<br /> +--------------------+ phP100.Com<br /> | @@query_cache_size |<br /> +--------------------+<br /> | 16777216 |<br /> +--------------------+<br /> 1 row in set (0.00 sec)<br />   查看最大缓存结果,如果结果集大于该数,不缓存。<br /> <br /> MySQL&gt; select @@global.query_cache_limit;<br /> +----------------------------+<br /> | @@global.query_cache_limit |<br /> +----------------------------+<br /> | 1048576 |<br /> +----------------------------+<br /> 1 row in set (0.00 sec)<br />   碎片整理<br /> <br /> MySQL&gt; flush query cache<br /> -&gt; ;<br /> Query OK, 0 rows affected (0.00 sec)<br />   清除缓存<br /> <br /> MySQL&gt; reset query cache phP100.Com<br /> -&gt; ;<br /> Query OK, 0 rows affected (0.00 sec<br />   监视MySQL 查询缓存性能:<br /> <br /> MySQL&gt; flush tables;<br /> Query OK, 0 rows affected (0.04 sec)<br /> MySQL&gt; show status like &#39;qcache%&#39;;<br /> +-------------------------+----------+<br /> | Variable_name | Value |<br /> +-------------------------+----------+<br /> | Qcache_free_blocks | 1 |<br /> | Qcache_free_memory | 16768408 |<br /> | Qcache_hits | 6 |<br /> | Qcache_inserts | 36 | PhP100.Com<br /> | Qcache_lowmem_prunes | 0 |<br /> | Qcache_not_cached | 86 |<br /> | Qcache_queries_in_cache | 0 |<br /> | Qcache_total_blocks | 1 |<br /> +-------------------------+----------+<br /> 8 rows in set (0.06 sec)<br />   看看当前缓存中有多少条信息:<br /> <br /> MySQL&gt; show status like &#39;qcache_q%&#39;;<br /> +-------------------------+-------+<br /> | Variable_name | Value |<br /> +-------------------------+-------+<br /> | Qcache_queries_in_cache | 0 |<br /> +-------------------------+-------+<br /> 1 row in set (0.00 sec)<br /> MySQL&gt; select sql_cache id, title, body from article;<br /> MySQL&gt; show status like &#39;qcache_q%&#39;; PhP100.Com<br /> +-------------------------+-------+<br /> | Variable_name | Value |<br /> +-------------------------+-------+<br /> | Qcache_queries_in_cache | 1 |<br /> +-------------------------+-------+<br /> 1 row in set (0.00 sec)<br /> MySQL&gt; show status like &#39;qcache_f%&#39;;<br /> +--------------------+----------+<br /> | Variable_name | Value |<br /> +--------------------+----------+ PhP100.cOm<br /> | Qcache_free_blocks | 1 |<br /> | Qcache_free_memory | 16766728 |<br /> +--------------------+----------+<br /> 2 rows in set (0.00 sec)<br />   以上的相关内容就是对MySQL 查询缓存的介绍,望你能有所收获。<br /> </p>
T:0.007930s,M:207.53 KB
返回顶部 留言