ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
#### 什么是查询缓存 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)