您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2024/5/30 10:48:41发布15次查看
mysql查询
以下的文章主要介绍的是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 like '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_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  -> ;  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 |   | 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%';  +-------------------------+-------+  | variable_name | value |  +-------------------------+-------+  | qcache_queries_in_cache | 1 |   +-------------------------+-------+  1 row in set (0.00 sec)  mysql> show status like 'qcache_f%';  +--------------------+----------+  | variable_name | value |  +--------------------+----------+  | qcache_free_blocks | 1 |   | qcache_free_memory | 16766728 |   +--------------------+----------+  2 rows in set (0.00 sec)  
以上的相关内容就是对mysql 查询缓存的介绍,望你能有所收获。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product