Archived post from my old blog (2007–2016), restored from the Wayback Machine. It is published as written at the time, in Italian; tools and versions are likely out of date.
Mysql QueryCache
Più per mia comodità che altro ripeto qui la procedura per attivare la query cache di MySql
nel my.cnf
nella sezione [mysqld]
query_cache_type = 1 query_cache_size = 20M
Il tipo di caching è:
- Tutto quello che al demone pare corretto tenere in cache oltre a quelli esplicitamente aggiunti tramite la clausola SQL_CACHE e meno quelli esplicitamente esclusi tramite la clausola SQL_NO_CACHE
- Solo quello che è esplicitamente indicato tramite la clausola SQL_CACHE
Va da sè che se la dimensione della cache è a zero il caching non funzionerà.
La dimensione minima della cache mi pare che sia di 4kb, ma ovviamente non riuscirebbe a tenere nulla. Un valore realistico è di qualche mega.
Per controllare se funziona dopo il restart del demone basta fare come segue
mysql> SHOW STATUS LIKE '%qcache%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 12 |
| Qcache_free_memory | 26096368 |
| Qcache_hits | 317 |
| Qcache_inserts | 218 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 15 |
| Qcache_queries_in_cache | 69 |
| Qcache_total_blocks | 160 |
+-------------------------+----------+
8 rows in set (0.12 sec)
mysql> SHOW VARIABLES LIKE '%query%';
+------------------------------+----------+
| Variable_name | Value |
+------------------------------+----------+
| ft_query_expansion_limit | 20 |
| have_query_cache | YES |
| long_query_time | 10 |
| query_alloc_block_size | 8192 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 26214400 |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | 8192 |
+------------------------------+----------+
10 rows in set (0.10 sec)← Archive