+-------------------------+--------+
8 rows in set (0.00 sec)
From this, you can see that only 18 queries are in the cache
(Qcache_queries_in_cache); you have 169,544 bytes of memory free
in the cache (Qcache_free_memory), 698 queries have been read from
the cache (Qcache_hits), and 38 queries have been inserted into the cache
(Qcache_inserts), but 20 of them were removed due to lack of memory
(Qcache_lowmem_prunes), giving the 18 from before.
Qcache_not_cached is 0, which means 0 queries were not cached;
MySQL is caching them all.
From all this, you can calculate how many total queries came in; it is the sum
of Qcache_hits, Qcache_inserts, and Qcache_not_cached,
which is 736. You can also calculate how well the query cache is being used
by dividing Qcache_hits by that number and multiplying by 100. In this
case, 94.84% of all queries are being served from the query cache, which is a
great number.
In this example, you can see that many queries have been trimmed because
there is not enough memory in the query cache. This can be changed by
editing your /etc/my.cnf file and adding a line like this one somewhere
in the [mysqld] section:
Click here to view code image
set-variable = query_cache_size=32M
An 8MB query cache should be enough for most people, but larger sites
might need 16MB or even 32MB if you are storing a particularly large
amount of data. Very few sites will need to go beyond a 32MB query cache,
but keep an eye on the Qcache_lowmem_prunes value to ensure that you
have enough RAM allocated.
Using the query cache does not incur much of a performance hit. When
MySQL calculates the result of a query normally, it throws it away when the
connection closes. With the query cache, it skips the throwing away, and so
there is no extra work being done. If your site does have many updates and
deletes, be sure to check whether you get any speed boost at all from the
query cache.
Miscellaneous Tweaks
If you have tuned your key buffer and optimized your query cache and yet
still find your site struggling, you can make a handful of smaller changes that