How to disable query caching in MYSQL?

Asked

Viewed 617 times

1

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

Upshot:

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

How do I disable this directive? Is there a command for me to disable the automatic cache of queries?

1 answer

2


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

  • Disconnected: query_cache_type = 0
  • Connected to all query’s: query_cache_type = 1
  • On-demand: query_cache_type = 2

To change the value you can execute the following command:

 SET SESSION query_cache_type=0;

or

SET GLOBAL query_cache_type=OFF;

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

SELECT SQL_NO_CACHE * FROM table.

And to use the cache just use the SQL_CACHE.

SELECT SQL_CACHE * FROM table.

References:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.