The actual application code of MySQL to query Cache

Source: Internet
Author: User

The following articles mainly describe the actual operation steps for MySQL to query cache and the description of more than 20 application codes of MySQL to query cache, the following describes how to view the cache size and monitor its performance.

 
 
  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)  

View the cache size of a MySQL Query

 
 
  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)   

View the maximum number of cached results. If the number of result sets is greater than this value, the results are not cached.

 
 
  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) 

Fragment

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

Clear Cache

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

Monitor MySQL query cache performance:

 
 
  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) 

Check the number of items in the current cache:

 
 
  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)  

The above content is an introduction to MySQL query cache. I hope you will get some benefits.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.