mysql5.7 mysql配置文件my.cnf 中 query_cache_min_res_unit 的优化

开启了数据库缓存后用 show status like 'qcache%';   #查看缓存query_cache_min_res_unit  默认是4k

发现  Qcache_free_blocks  数目大 说明可能有碎片。

mysql> show status like 'qcache%';
+-------------------------+-----------+
| Variable_name           | Value     |
+-------------------------+-----------+
| Qcache_free_blocks      | 9589      |
| Qcache_free_memory      | 119423544 |
| Qcache_hits             | 4636973   |
| Qcache_inserts          | 1106053   |
| Qcache_lowmem_prunes    | 0         |
| Qcache_not_cached       | 24856     |
| Qcache_queries_in_cache | 13205     |
| Qcache_total_blocks     | 36077     |
+-------------------------+-----------+
8 rows in set (0.01 sec)

Qcache_free_blocks:表示查询缓存中目前还有多少剩余的blocks,如果该值显示较大,则说明查询缓存中的内存碎片过多了,可能在一定的时间进行整理。    减少碎片: 合适的query_cache_min_res_unit可以减少碎片,这个参数最合适的大小和应用程序查询结果的平均大小直接相关,

可以通过内存实际消耗( query_cache_size - Qcache_free_memory )除以 Qcache_queries_in_cache 计算平均缓存大小。

其中 Qcache_free_memory 和 Qcache_queries_in_cache  在上面已将有了 分别是119423544 和 13205 

query_cache_size 是自己设置的可以通过 

SHOW VARIABLES LIKE '%query_cache%'; 查看

query_cache_size - Qcache_free_memory )除以 Qcache_queries_in_cache

就是 (134217728 - 119423544)/13205=1120.34

所以在设置的的时候 query_cache_min_res_unit 可以设置成2k  在my.cnf中

query_cache_min_res_unit= 2k

然后在查看他的Qcache_free_blocks运行一段时间有没有减少

猜你喜欢

转载自blog.csdn.net/z13615480737/article/details/82621116