#### 什么是查询缓存
mysql服务器提供的,用于缓存select语句结果的一种内部内存缓存系统。如果开启了查询缓存,将所有的查询结果,都缓存起来,使用同样的select语句,再次查询时,直接返回缓存的结果即可.
#### 查看缓存设置
~~~
show variables like 'query_cache%';
~~~
~~~
+------------------------------+---------+
| Variable_name | Value |
+------------------------------+---------+
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 0 | //缓存空间大小
| query_cache_type | OFF | //是否有开启缓存
| query_cache_wlock_invalidate | OFF |
+------------------------------+---------+
~~~
#### 开启查询缓存
在my.ini文件中:
1为开启.
![](https://box.kancloud.cn/c9eff3029dac9dfd0291e78c6e3fa5e6_754x96.png)
单位是字节,换算为128M.
![](https://box.kancloud.cn/277840c237462d67249be61346db1f66_647x114.png)
修改完文件后重启mysql服务.
#### 查看
~~~
+------------------------------+-----------+
| Variable_name | Value |
+------------------------------+-----------+
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 134217728 |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
+------------------------------+-----------+
~~~
这样就可以使用查询缓存了.
#### 查看缓存空间使用情况
~~~
show status like 'Qcache%';
~~~
~~~
+-------------------------+-----------+
| Variable_name | Value |
+-------------------------+-----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 134197296 |
| Qcache_hits | 3 |
| Qcache_inserts | 2 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 5 |
| Qcache_queries_in_cache | 2 |
| Qcache_total_blocks | 7 |
+-------------------------+-----------+
~~~
![](https://box.kancloud.cn/cbe896cd71380d79eb6b131117a0b65e_827x299.png)
- MySQL优化概述
- 存储引擎的选择
- innodb引擎
- myisam引擎
- memory引擎
- 查询需优化语句
- 通用查询日志
- 慢查询日志
- profile机制
- 索引
- 索引基本介绍
- 索引类型
- 索引管理语法
- 创建索引主要事项
- 执行计划
- 查看索引类型
- myisam索引数据结构
- innodb索引数据结构
- 索引覆盖
- 索引使用原则
- 列独立
- like查询
- 复合索引使用
- or运算都具有索引
- mysql智能选择
- 优化group by语句
- 前缀索引
- 全文索引
- 查询缓存
- 查询缓存操作
- 无缓存
- limit分页优化
- 分区
- 分区介绍
- list分区
- range分区
- hash分区
- key(键值)分区
- 分区管理
- 分表
- 分表介绍
- 水平分表
- 垂直分表
- MySQL锁机制
- 锁机制介绍
- 锁的几种形式
- 表锁操作
- 行锁操作
- 数据碎片与维护
- 范式
- 第一范式
- 第二范式
- 第三范式
- 反三范式
- 主从复制
- 介绍
- 读写分离