Configuring caching in MySQL can significantly enhance database performance by reducing query execution times. Below are the steps to configure caching in MySQL:
1. Enable Query Cache
The query cache is used to store the results of SELECT queries. If the same query is executed again, MySQL can return the cached result without re-executing the query.
Steps:
-
Check if the query cache is enabled:
SHOW VARIABLES LIKE 'query_cache%';
-
Enable and configure query cache in the MySQL configuration file (
my.cnf
ormy.ini
):[mysqld] query_cache_type = 1 # 1 = ON, 2 = DEMAND (only cache queries with SQL_CACHE) query_cache_size = 128M # Set the size of the query cache query_cache_limit = 2M # Maximum size of individual query results to cache
-
Restart the MySQL service to apply changes: