Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - force not to use cache for testing speed of query

Tags:

mysql

People also ask

How do I disable MySQL query cache?

Query to disable the cache From the MySQL command line, a application like phpMyAdmin, or from a script, run the following SQL command to disable the query cache: SET GLOBAL query_cache_size = 0; This will take effect immediately. You will also need to modify the MySQL configuration file to keep it disabled on reboot.

Why is MySQL query cache deprecated?

The query cache has been disabled-by-default since MySQL 5.6 (2013) as it is known to not scale with high-throughput workloads on multi-core machines. Rene confirmed this in his post yesterday, but it has also previously been mentioned by Stewart Smith, Domas Mituzas (update: and Kristian Koehntopp).

Does caching improve query performance?

As an example, for a WordPress site or an e-commerce portal with high read calls and infrequent data changes, query cache can drastically boost the performance of the database server and make it more scalable.


Try using the SQL_NO_CACHE (MySQL 5.7) option in your query. (MySQL 5.6 users click HERE )

eg.

SELECT SQL_NO_CACHE * FROM TABLE

This will stop MySQL caching the results, however be aware that other OS and disk caches may also impact performance. These are harder to get around.


Another alternative that only affects the current connection:

SET SESSION query_cache_type=0;

Any reference to current date/time will disable the query cache for that selection:

SELECT *,NOW() FROM TABLE

See "Prerequisites and Notes for MySQL Query Cache Use" @ http://dev.mysql.com/tech-resources/articles/mysql-query-cache.html


There is also configuration option: query_cache_size=0

To disable the query cache at server startup, set the query_cache_size system variable to 0. By disabling the query cache code, there is no noticeable overhead. If you build MySQL from source, query cache capabilities can be excluded from the server entirely by invoking configure with the --without-query-cache option.

See http://dev.mysql.com/doc/refman/5.1/en/query-cache.html


You can also run the follow command to reset the query cache.

RESET QUERY CACHE