Skip to main content
Documents
Clauses StatementsKeywordsExpressionsFunctionsIndexesPerformance Optimization

MySQL Query Cache Deprecation in MySQL 8 Performance Optimization

The query cache in MySQL was a feature used to store the result of SELECT queries to improve performance by reducing database load. In MySQL 8, this feature has been completely removed as part of performance optimization, due to its inefficiencies and the advent of better caching mechanisms.

Usage

The query cache was used to speed up data retrieval for repeated queries by caching their results. It was typically enabled in MySQL server configuration, but in MySQL 8, support has been fully deprecated and removed. The query cache was considered inefficient because it could lead to increased contention and overhead, particularly in environments with frequent data modifications, which required invalidating cached results.

Syntax Prior to MySQL 8

SET GLOBAL query_cache_size = 1000000;

This configuration set the size of the query cache globally, though it is no longer applicable in MySQL 8.

Examples

1. Enabling Query Cache (Pre-MySQL 8)

SET GLOBAL query_cache_type = ON;

This command was used to turn on the query cache, allowing MySQL to cache query results. This is not valid in MySQL 8.

2. Checking Cache Status (Pre-MySQL 8)

SHOW VARIABLES LIKE 'query_cache%';

This query retrieved the status and settings of query cache parameters. It is useful for monitoring but is not applicable in MySQL 8.

3. Managing Query Cache (Pre-MySQL 8)

RESET QUERY CACHE;

This command was used to clear the query cache manually. It helped in refreshing the cache when necessary but is obsolete in MySQL 8.

Tips and Best Practices

  • Switch to application-level caching. Use application-side caching mechanisms like Memcached or Redis for better scalability.
  • Utilize database indices. Optimize queries by creating efficient indices to reduce the need for query caching.
  • Leverage other MySQL 8 features. MySQL 8's improved optimizer and execution plans enhance performance by providing more accurate query cost estimations and better execution strategies.
  • Consider using caching plugins. If needed, utilize plugins or third-party tools designed for caching in MySQL environments.
  • Identify and refactor reliance on query cache. Review and update applications to ensure they do not depend on query cache behavior, and adjust performance monitoring practices to align with MySQL 8 optimizations.

SQL Upskilling for Beginners

Gain the SQL skills to interact with and query your data.
Start Learning for Free