国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > MySQL > 正文

MySQL 查詢緩存的實際應用代碼示例

2024-07-24 13:00:48
字體:
供稿:網(wǎng)友

以下的文章主要介紹的是MySQL 查詢緩存的實際應用代碼以及查看MySQL 查詢緩存的大小 ,碎片整理,清除緩存以及監(jiān)視MySQL 查詢緩存性能的相關(guān)內(nèi)容的描述,以下就是具體內(nèi)容的描述,希望在你今后的學習中會有所幫助。

  1. MySQL> select @@query_cache_type;  
  2. +--------------------+  
  3. | @@query_cache_type |  
  4. +--------------------+  
  5. | ON |   
  6. +--------------------+  
  7. MySQL> set query_cache_type=off;  
  8. MySQL> set query_cache_type=on;  
  9. MySQL>   
  10. MySQL> select sql_cache id, title, body from article;  
  11. MySQL> select sql_no_cache id, title, body from article;  
  12. MySQL> show variables like 'have_query_cache';  
  13. +------------------+-------+  
  14. | Variable_name | Value |  
  15. +------------------+-------+  
  16. | have_query_cache | YES |   
  17. +------------------+-------+  
  18. 1 row in set (0.00 sec)  

  查看MySQL 查詢緩存的大小

  1. MySQL> select @@global.query_cache_size;  
  2. +---------------------------+  
  3. | @@global.query_cache_size |  
  4. +---------------------------+  
  5. | 16777216 |   
  6. +---------------------------+  
  7. 1 row in set (0.00 sec)  
  8. MySQL> select @@query_cache_size;  
  9. +--------------------+  
  10. | @@query_cache_size |  
  11. +--------------------+  
  12. | 16777216 |   
  13. +--------------------+  
  14. 1 row in set (0.00 sec) 

  查看最大緩存結(jié)果,如果結(jié)果集大于該數(shù),不緩存。

  1. MySQL> select @@global.query_cache_limit;  
  2. +----------------------------+  
  3. | @@global.query_cache_limit |  
  4. +----------------------------+  
  5. | 1048576 |   
  6. +----------------------------+  
  7. 1 row in set (0.00 sec) 

  碎片整理

  1. MySQL> flush query cache  
  2. -> ;  
  3. Query OK, 0 rows affected (0.00 sec) 

  清除緩存

  1. MySQL> reset query cache  
  2. -> ;  
  3. Query OK, 0 rows affected (0.00 sec

  監(jiān)視MySQL 查詢緩存性能:

  1. MySQL> flush tables;  
  2. Query OK, 0 rows affected (0.04 sec)  
  3. MySQL> show status like 'qcache%';  
  4. +-------------------------+----------+  
  5. | Variable_name | Value |  
  6. +-------------------------+----------+  
  7. | Qcache_free_blocks | 1 |   
  8. | Qcache_free_memory | 16768408 |   
  9. | Qcache_hits | 6 |   
  10. | Qcache_inserts | 36 |   
  11. | Qcache_lowmem_prunes | 0 |   
  12. | Qcache_not_cached | 86 |   
  13. | Qcache_queries_in_cache | 0 |   
  14. | Qcache_total_blocks | 1 |   
  15. +-------------------------+----------+  
  16. 8 rows in set (0.06 sec)  

  看看當前緩存中有多少條信息:

  1. MySQL> show status like 'qcache_q%';  
  2. +-------------------------+-------+  
  3. | Variable_name | Value |  
  4. +-------------------------+-------+  
  5. | Qcache_queries_in_cache | 0 |   
  6. +-------------------------+-------+  
  7. 1 row in set (0.00 sec)  
  8. MySQL> select sql_cache id, title, body from article;  
  9. MySQL> show status like 'qcache_q%';  
  10. +-------------------------+-------+  
  11. | Variable_name | Value |  
  12. +-------------------------+-------+  
  13. | Qcache_queries_in_cache | 1 |   
  14. +-------------------------+-------+  
  15. 1 row in set (0.00 sec)  
  16. MySQL> show status like 'qcache_f%';  
  17. +--------------------+----------+  
  18. | Variable_name | Value |  
  19. +--------------------+----------+  
  20. | Qcache_free_blocks | 1 |   
  21. | Qcache_free_memory | 16766728 |   
  22. +--------------------+----------+  
  23. 2 rows in set (0.00 sec)  

  以上的相關(guān)內(nèi)容就是對MySQL 查詢緩存的介紹,望你能有所收獲。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 岱山县| 吉木萨尔县| 江西省| 西林县| 木兰县| 新巴尔虎右旗| 安多县| 历史| 会东县| 鹤壁市| 楚雄市| 华安县| 涪陵区| 托里县| 新和县| 固阳县| 廊坊市| 和田市| 株洲县| 卢湾区| 文成县| 林西县| 余江县| 阳江市| 东乌珠穆沁旗| 济阳县| 曲沃县| 永城市| 满城县| 泰州市| 岳阳县| 潜江市| 晋宁县| 民丰县| 安多县| 溧水县| 南丹县| 湟源县| 龙游县| 松江区| 曲阳县|