Prevent a MySQL query from using the query cache

Whilst I was busy trying to optimize a MySQL query I got annoyed by the fact that when you make use of MySQL’s query cache that a query gets cached. When that happens a second time you execute the query it’s being looked up and the cached results are being returned. If you want to optimize a query and test its performance this can be quite annoying.

Luckily I found out there’s an easy solution to this problem. Just make use of SQL_NO_CACHE┬álike this:


Now when you run this query it makes sure MySQL doesn’t store it in its query cache.

Scroll to Top