从mysql4.1版本之后新增的功能。
作用:存储select查询的文本以及相应结果。如果随后收到一个相同的查询,则不再解析和执行查询,而是直接从缓存中得到查询结果。
mysql> show variables like '%query_cache%';
+------------------------------+---------+
| Variable_name | Value |
+------------------------------+---------+
| have_query_cache | YES |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 1048576 |
| query_cache_type | OFF |
| query_cache_wlock_invalidate | OFF |
+------------------------------+---------+
6 rows in set (0.00 sec)
变量 | 例子 | 描述 |
---|---|---|
have_query_cache | YES | 表明服务器在安装时是否配置了告诉缓存 |
query_cache_limit | 1048576 | |
query_cache_min_res_unit | 4096 | |
query_cache_size | 1048576 | 表明缓存区的大小,单位为MB |
query_cache_type | OFF | 变量从0到2,1或者off(缓存关闭),1或者on(缓存打开,使用SQL_NOCACHE提示的select除外),2或者demand(只带有SQL_CACHE的select语句提供高速缓存) |
query_cache_wlock_invalidate | OFF |
缓存监控
mysql> show status like '%Qcache%';
+-------------------------+---------+
| Variable_name | Value |
+-------------------------+---------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 1031352 |
| Qcache_hits | 0 |
| Qcache_inserts | 0 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 33048 |
| Qcache_queries_in_cache | 0 |
| Qcache_total_blocks | 1 |
+-------------------------+---------+
8 rows in set (0.00 sec)
Variable_name | Value | 描述 |
---|---|---|
Qcache_free_blocks | 1 | 查询缓存中的空闲内存块的数目 |
Qcache_free_memory | 1031352 | 查询缓存的空闲内存数 |
Qcache_hits | 0 | 缓存采样数数目 |
Qcache_inserts | 0 | 被加入到缓存中的查询数目 |
Qcache_lowmem_prunes | 0 | 因为缺少内存而被删除的查询数目 |
Qcache_not_cached | 33048 | 没有被缓存的查询数目(不能被缓存的,或由于QUERY_CACHE_TYPE) |
Qcache_queries_in_cache | 0 | 在缓存中已注册的查询数目TYPE |
Qcache_total_blocks | 1 | 查询缓存中的块的总数目 |