Read more

MySQL: Disable query cache for database profiling

Tobias Kraze
October 04, 2010Software engineer at makandra GmbH

If you want to see how long your database queries actually take, you need to disable MySQL's query cache. This can be done globally by logging into a database console, run

SET GLOBAL query_cache_type=OFF;
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show snapshot

and restart your rails server.

You can also disable the cache on a per query basis by saying


You also probably want to disable Rails internal (per-request) cache. For this, wrap your code with a call to ActiveRecord::Base.uncached. For example, as an around_filter:

def disable_cache
  ActiveRecord::Base.uncached do

Don't forget to re-enable MySQL query caching later with

SET GLOBAL query_cache_type=ON;
Posted by Tobias Kraze to makandra dev (2010-10-04 16:39)