How to Enable Query Cache in MySQL

Query caches are useful as far as the database performance is concerned, as it makes a cache of the used queries and thus can fetch the data quickly.
In this tutorial we will learn to enable the mysql query cache feature.

Step 1- MySQL Folder
To enable mysql query caching, first of all, open up the “my.ini” file in the MySQL instance.
As we are using WAMP server, we will simply click on its icon on the taskbar, then go to MySQL and click on the “my.ini” file.

Locating my.ini File

Step 2- Modifying the File
With the file opened up, scroll down to the bottom and just add the following lines:
With that done, just save the file and close it.

Adding Cache configurations

Step 3- Restarting Wamp Services
After that, we have to restart all our Wamp services.
Wait for the Wamp icon to turn green again.

Restarting the Server

Step 4- Opening the Console
Now open up the MySQL console to verify the working of mysql query cache feature.

MySQL Console

Step 5- Cache Statistics
With the console opened up, write the following query:
SHOW VARIABLES LIKE ‘%query_cache%’;
A table would appear and next to the query cache option, the value would be “YES” which means that the feature has been enabled.

Cache Options

And this is how we can enable mysql query caching feature.