在這裡簡單介紹一下MariaDB的緩存相關參數。
have_query_cache
MariaDB [(none)]> SHOW VARIABLES LIKE 'have_query_cache';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| have_query_cache | YES |
+------------------+-------+
1 row in set (0.00 sec)
query_cache_limit
MariaDB [(none)]> SHOW VARIABLES LIKE 'query_cache_limit';
+-------------------+---------+
| Variable_name | Value |
+-------------------+---------+
| query_cache_limit | 1048576 |
+-------------------+---------+
1 row in set (0.00 sec)
query_cache_min_res_unit
SHOW VARIABLES LIKE 'query_cache_min_res_unit';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| query_cache_min_res_unit | 4096 |
+--------------------------+-------+
1 row in set (0.00 sec)
query_cache_size
MariaDB [(none)]> SHOW VARIABLES LIKE 'query_cache_size';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| query_cache_size | 0 |
+------------------+-------+
1 row in set (0.00 sec)
query_cache_type
MariaDB [(none)]> SHOW VARIABLES LIKE 'query_cache_type';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| query_cache_type | ON |
+------------------+-------+
1 row in set (0.00 sec)
query_cache_wlock_invalidate
MariaDB [(none)]> SHOW VARIABLES LIKE 'query_cache_wlock_invalidate';
+------------------------------+-------+
| Variable_name | Value |
+------------------------------+-------+
| query_cache_wlock_invalidate | OFF |
+------------------------------+-------+
1 row in set (0.00 sec)
確認查詢緩存情況
如何確認一個數據庫的查詢緩存情況,如命中率如何,配置的內存是否妥當?
MariaDB提供了一系列的SHOW STATUS命令來確認當前的查詢緩存狀態。
MariaDB [(none)]> SHOW STATUS LIKE 'Qcache%';
+-------------------------+-------+
| Variable_name | Value |
+-------------------------+-------+
| Qcache_free_blocks | 0 |
| Qcache_free_memory | 0 |
| Qcache_hits | 0 |
| Qcache_inserts | 0 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 0 |
| Qcache_queries_in_cache | 0 |
| Qcache_total_blocks | 0 |
+-------------------------+-------+
8 rows in set (0.00 sec)
清除查詢緩存
MariaDB [(none)]> RESET QUERY CACHE;
Query OK, 0 rows affected (0.00 sec)