View query cache condition:mysql> show variables like '%query_cache% '; (Query_cache_type for on indicates already on) +------------------------- -----+----------+| Variable_name | Value |+------------------------------+----------+| Have_query_cache | YES | | Query_cache_limit | 1048576 | | Query_cache_min_res_unit | 4096 | | Query_cache_size | 20971520 | | Query_cache_type | On | | Query_cache_wlock_invalidate | OFF |+------------------------------+----------+ if not on, modify the configuration file to open the query cache:> vi /etc/ MY.CNF[MYSQLD] Added: query_cache_size = 20mquery_cache_type = on Restart MySQL Services:> service MySQL restart View cache usage:mysql> show status like ' qcache% '; +-------------------------+----------+| Variable_name | Value |+-------------------------+----------+| Qcache_free_blocks | | | Qcache_free_memory | 19811040 | | Qcache_hits | 3108196 | | Qcache_inserts | 757254 | | Qcache_lowmem_prunes | 20720 | | qcache_not_cached | 47219 | | Qcache_queries_in_cache | | | Qcache_total_blocks | 276 |+-------------------------+----------+
The meanings of each of these parameters are as follows:
- Qcache_free_blocks: The number of contiguous memory blocks in the cache. A large number indicates that there may be fragmentation. FLUSH QUERY Cache organizes the fragments in the cache to get a free block.
- Qcache_free_memory: Free memory in the cache.
- Qcache_hits: Increases each time the query hits the cache
- Qcache_inserts: Increases each time a query is inserted. The number of hits divided by the number of inserts is not the ratio.
- Qcache_lowmem_prunes: The number of times that the cache is out of memory and must be cleaned up to provide space for more queries. This number is best seen over a long period of time, and if the number is growing, it can mean that fragmentation is very serious, or that there is little memory. (The above free_blocks and free_memory can tell you which kind of situation)
- Qcache_not_cached: The number of queries that are not appropriate for caching, usually because these queries are not a SELECT statement or are using functions such as now ().
- Qcache_queries_in_cache: The number of queries (and responses) that are currently cached.
- Qcache_total_blocks: The number of blocks in the cache.
For some statements that do not want to use the cache, you can use this: Select Sql_no_cache count (*) from the users where email = ' Hello ';
MySQL to see if the query cache is enabled