MySQL 配置优化(多个参数)

2019-01-03 22:57:33于海丽

举例如下:

mysql> show global status like ‘qcache%‘;
+——————————-+—————–+
| Variable_name                  | Value        |
+——————————-+—————–+
| Qcache_free_blocks        | 22756       |
| Qcache_free_memory     | 76764704    |
| Qcache_hits           | 213028692 |
| Qcache_inserts         | 208894227   |
| Qcache_lowmem_prunes   | 4010916      |
| Qcache_not_cached | 13385031    |
| Qcache_queries_in_cache | 43560 |
| Qcache_total_blocks          | 111212      |
+——————————-+—————–+
mysql> show variables like ‘query_cache%‘;
+————————————–+————–+
| Variable_name            | Value      |
+————————————–+———–+
| query_cache_limit         | 2097152     |
| query_cache_min_res_unit      | 4096    |
| query_cache_size         | 203423744 |
| query_cache_type        | ON           |
| query_cache_wlock_invalidate | OFF   |
+————————————–+—————+

查询缓存碎片率= Qcache_free_blocks / Qcache_total_blocks * 100%

如果查询缓存碎片率超过20%,可以用FLUSH QUERY CACHE整理缓存碎片,或者试试减小query_cache_min_res_unit,如果你的查询都是小数据量的话。

查询缓存利用率= (query_cache_size – Qcache_free_memory) / query_cache_size * 100%

查询缓存利用率在25%以下的话说明query_cache_size设置的过大,可适当减小;查询缓存利用率在80%以上而且Qcache_lowmem_prunes > 50的话说明query_cache_size可能有点小,要不就是碎片太多。

查询缓存命中率= (Qcache_hits – Qcache_inserts) / Qcache_hits * 100%

示例服务器查询缓存碎片率=20.46%,查询缓存利用率=62.26%,查询缓存命中率=1.94%,命中率很差,可能写操作比较频繁吧,而且可能有些碎片。

每个连接的缓冲

6)    record_buffer_size
每个进行一个顺序扫描的线程为其扫描的每张表分配这个大小的一个缓冲区。如果你做很多顺序扫描,你可能想要增加该值。

默认数值是131072(128K),可改为16773120 (16M)

7)     read_rnd_buffer_size