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

来源:Asp之家 时间:2010-06-11 12:04:00 

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

MySQL> select @@query_cache_type;

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

| @@query_cache_type |

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

| ON |

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

MySQL> set query_cache_type=off;

MySQL> set query_cache_type=on; php100.Com

MySQL>

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

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

MySQL> show variables like 'have_query_cache';

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

| Variable_name | Value |

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

| have_query_cache | YES |

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

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;

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

| @@query_cache_size |

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

| 16777216 |

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

1 row in set (0.00 sec)

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

MySQL> select @@global.query_cache_limit;

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

| @@global.query_cache_limit |

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

| 1048576 |

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

1 row in set (0.00 sec)

碎片整理

MySQL> flush query cache

-> ;

Query OK, 0 rows affected (0.00 sec)

清除缓存

MySQL> reset query cache phP100.Com

-> ;

Query OK, 0 rows affected (0.00 sec

监视MySQL 查询缓存性能:

MySQL> flush tables;

Query OK, 0 rows affected (0.04 sec)

MySQL> show status like 'qcache%';

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

| 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 |

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

8 rows in set (0.06 sec)

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

MySQL> show status like '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 like 'qcache_q%'; PhP100.Com

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

| Variable_name | Value |

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

| Qcache_queries_in_cache | 1 |

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

1 row in set (0.00 sec)

MySQL> show status like 'qcache_f%';

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

| Variable_name | Value |

+--------------------+----------+ PhP100.cOm

| Qcache_free_blocks | 1 |

| Qcache_free_memory | 16766728 |

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

2 rows in set (0.00 sec)

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

标签:mysql,缓存,数据库
0
投稿

猜你喜欢

  • 纯CSS图片预加载

    2009-10-28 18:40:00
  • js和asp操作fso比较

    2007-09-23 09:17:00
  • asp超强的Server Application Error 的解决方法

    2008-11-13 13:04:00
  • 如何把图片上传到数据库中并显示出来?

    2009-11-06 13:50:00
  • asp 过滤尖括号内所有内容的正则代码

    2011-04-03 10:40:00
  • br玩转清除浮动

    2007-05-11 16:52:00
  • Asp 操作Cookies(包括设置[赋值]、读取、删除[设置过期时间])

    2011-03-10 11:06:00
  • getWindow与isWindow

    2009-12-28 13:12:00
  • 写给JavaScript库开发者们的规则

    2008-10-26 12:30:00
  • 表单制作方式大比拼

    2008-10-09 11:32:00
  • 巧用SQL链接服务器访问远程Access数据库

    2008-11-28 16:32:00
  • Hibernate Oracle sequence的使用技巧

    2009-06-19 17:25:00
  • asp中通过addnew添加内容后取得当前文章的自递增ID的方法

    2011-02-05 11:05:00
  • jQuery性能优化指南[译]

    2009-05-12 11:54:00
  • 数据库分页大全(mssql,mysql,oracle)

    2010-10-25 20:02:00
  • 以独占方式打开Access数据库

    2007-10-22 12:24:00
  • 用MSXML2.ServerXMLHTTP的setTimeouts属性解决并死问题

    2010-03-02 20:21:00
  • 区别div和span、relative和absolute、display和visibility

    2009-12-13 12:18:00
  • 浅谈SQL与PLSQL开发实战

    2011-05-05 08:15:00
  • SQL行号排序和分页(SQL查询中插入行号 自定义分页的另类实现)

    2012-07-21 14:45:15
  • asp之家 网络编程 m.aspxhome.com