HI Buddies,
I leaned something new about Mysql Query caching.
Indeed it would be good to be able to see query cache contents.
Unfortunately it is not possible in current MySQL version. So you’ve just got to guess.
SESSION shows the values for the current connection.
mysql> SHOW GLOBAL STATUS;
+———————————–+————+
| Variable_name | Value |
+———————————–+————+
| Aborted_clients | 0 |
| Aborted_connects | 0 |
| Bytes_received | 155372598 |
| Bytes_sent | 1176560426 |
…
| Connections | 30023 |
| Created_tmp_disk_tables | 0 |
| Created_tmp_files | 3 |
| Created_tmp_tables | 2 |
…
| Threads_created | 217 |
| Threads_running | 88 |
| Uptime | 1389872 |
+———————————–+————+
#Qcache_free_memory -
The amount of free memory for the query cache.
#Qcache_hits -
The number of query cache hits.
#Qcache_inserts -
The number of queries added to the query cache.
#Qcache_queries_in_cache -
The number of queries registered in the query cache.
For Details Ref :- http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html#statvar_Qcache_free_memory
Byte to MB relation (16777216 bytes
16384.000 kilobytes (abbreviated as KB or Kb*)
16.0000 megabytes (abbreviated as M or MB))
To set the size of the query cache, set the query_cache_size system variable. Setting it to 0 disables the query cache.
When you set query_cache_size to a nonzero value, keep in mind that the query cache needs a minimum size of about 40KB to allocate its structures.
mysql> SET GLOBAL query_cache_size = 40000;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> SHOW WARNINGS\G
*************************** 1. row ***************************
Level: Warning
Code: 1282
Message: Query cache failed to set size 39936;
new query cache size is 0
mysql> SET GLOBAL query_cache_size = 41984;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE ‘query_cache_size’;
+——————+——-+
| Variable_name | Value |
+——————+——-+
| query_cache_size | 41984 |
+——————+——-+
For the query cache to actually be able to hold any query results, its size must be set larger:
mysql> SET GLOBAL query_cache_size = 1000000;
Query OK, 0 rows affected (0.04 sec)
mysql> SHOW VARIABLES LIKE ‘query_cache_size’;
+——————+——–+
| Variable_name | Value |
+——————+——–+
| query_cache_size | 999424 |
+——————+——–+
1 row in set (0.00 sec)
The query_cache_size value is aligned to the nearest 1024 byte block. The value reported may therefore be different from the value that you assign.
To control the maximum size of individual query results that can be cached, set the query_cache_limit system variable. The default value is 1MB.
Setting the GLOBAL query_cache_type value determines query cache behavior for all clients that connect after the change is made. Individual clients can control cache behavior for their own connection by setting the SESSION query_cache_type value. For example, a client can disable use of the query cache for its own queries like this:
mysql> SET SESSION query_cache_type = OFF;
If you set query_cache_type at server startup (rather than at runtime with a SET statement), only the numeric values are allowed.
query_cache_type = 2; means You can cache query on defmand using
SELECT SQL_CACHE id, name FROM customer;
SQL_CACHE
The query result is cached if it is cacheable and the value of the query_cache_type system variable is ON or DEMAND.
vice versa,
SELECT SQL_NO_CACHE id, name FROM customer;
The default value of query_cache_min_res_unit is 4KB. This should be adequate for most cases.
For details Ref : http://dev.mysql.com/doc/refman/5.0/en/query-cache-configuration.html
To check whether the query cache is present in your MySQL server, use the following statement:
mysql> SHOW VARIABLES LIKE ‘have_query_cache’;
+——————+——-+
| Variable_name | Value |
+——————+——-+
| have_query_cache | YES |
+——————+——-+
To monitor query cache performance, use SHOW STATUS to view the cache status variables:
mysql> SHOW STATUS LIKE ‘Qcache%’;
+————————-+——–+
| Variable_name | Value |
+————————-+——–+
| Qcache_free_blocks | 36 |
| Qcache_free_memory | 138488 |
| Qcache_hits | 79570 |
| Qcache_inserts | 27087 |
| Qcache_lowmem_prunes | 3114 |
| Qcache_not_cached | 22989 |
| Qcache_queries_in_cache | 415 |
| Qcache_total_blocks | 912 |
+————————-+——–+
The information provided by the Qcache_lowmem_prunes status variable can help you tune the query cache size. It counts the number of queries that have been removed from the cache to free up memory for caching new queries. The query cache uses a least recently used (LRU) strategy to decide which queries to remove from the cache
The optimal value of Qcache_lowmem_prunes is 0.
For details Ref : http://dev.mysql.com/doc/refman/5.0/en/query-cache-status-and-maintenance.html
Recent Comments