Home / Disable the MySQL query cache without restarting MySQL

Disable the MySQL query cache without restarting MySQL

The MySQL query cache enables caching of queries which, in theory, should speed querying the database up. It’s possible to disable the MySQL query cache without restarting the server, although you also need to edit the configuration file to make the changes stick on restart.

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. Locate the query_cache_size setting in the file and set it to 0.

I needed to do this today myself because one of the websites I manage kept getting locks which were preventing other queries from running, and we decided to shut off the query cache to see if it makes a difference. It’s too early so far to tell whether or not it has.

Check out the related posts below for more information about the query cache and how to enable it in the first place.