What Is Query Cache in MySQL
What Is Query Cache in MySQL
What Is Query Cache in MySQL
I need some help about MySQL query cache feature. I want to know, what is query cache and how to use it?
iii.
after the change is made. Each client can also control cache behavior for his own connection by setting the SESSION query_cache_type value. Take the following two examples, one for GLOBAL level and second for SESSION level:
SET GLOBAL query_cache_type = 1; //Enable query cache for all clients SET SESSION query_cache_type = 0; //Disable query cache for current client
In case of above query, the result of the query will not be cached. Similarly, you can enable query caching (on demand) by specifiying SQL_CACHE in your query like below:
SELECT SQL_CACHE book_id, book_name FROM books WHERE auhor_id = 9;
After execution of the above query, the result will be added to the cache memory and will be used if the same query is executed again.
In some cases queries are not cached. Any query making use of the following functions will not be cached:
User-Defined Functions GET_LOCK MASTER_POS_WAIT CURRENT_TIMESTAMP CURTIME ENCRYPT (with one parameter) UNIX_TIMESTAMP (without parameters) CONNECTION_ID RELEASE_LOCK NOW CURDATE CURRENT_TIME LAST_INSERT_ID USER FOUND_ROWS LOAD_FILE SYSDATE CURRENT_DATE DATABASE RAND BENCHMARK
queries contains user variables queries references the mysql system database queries like below: SELECT ... IN SHARE MODE SELECT ... FOR UPDATE SELECT ... INTO OUTFILE ... SELECT ... INTO DUMPFILE ... SELECT * FROM AUTOINCREMENT_FIELD IS NULL
Before a query result is fetched from the query cache, MySQL checks that the user has SELECT privilege for all databases and tables involved. If this is not the case, the cached result is not used.
DATABASE will clear the cache. However, MySQL also provides RESET QUERY CACHE command to clear query cache manually.