How to disable the query cache in MYSQL?

1

When we use the command SHOW VARIABLES LIKE 'have_query_cache' we can see if the cache is enabled or not.

Result:

Variable_name    | Value
----------------------------
have_query_cache | YES

How do I disable this policy? Is there a command so I can disable automatic caching of queries?

    
asked by anonymous 24.02.2016 / 14:06

1 answer

2

query_cache is divided into three types: On, off, and on demand.

  • Off: query_cache_type = 0
  • Linked to all queries: query_cache_type = 1
  • On demand: query_cache_type = 2

To change the value you can run the following command:

 SET SESSION query_cache_type=0;

or

SET GLOBAL query_cache_type=OFF;

You can use SQL_NO_CACHE to use on a specific query. It would look like this:

SELECT SQL_NO_CACHE * FROM table.

And just use the SQL_CACHE to use the cache. .

SELECT SQL_CACHE * FROM table.

References:

24.02.2016 / 14:07