query_cache_size in MySQL
MySQL's Query Cache was designed to store the results of frequently executed SELECT statements so that identical queries could be served without executing them again. The query_cache_size variable controlled the amount of memory allocated to this cache. (dev.mysql.com)
However, this feature is now historical: MySQL deprecated the Query Cache in MySQL 5.7.20 and removed it completely in MySQL 8.0. (dev.mysql.com)
What Was query_cache_size?
In MySQL 5.7 and earlier versions that supported the Query Cache, you could check its size using:
SHOW VARIABLES LIKE 'query_cache_size';
A larger value meant that more query results could potentially be stored in memory.
For workloads with many identical queries and relatively infrequently changing tables, the Query Cache could reduce repeated query execution. (dev.mysql.com)
Configure query_cache_size
In older MySQL configurations, it could be specified in the configuration file:
[mysqld]
query_cache_size=32M
The appropriate value depended on the workload and available memory.
However, increasing the cache was not automatically beneficial. Frequently modified tables could cause cached results to be invalidated, reducing the effectiveness of the cache. (dev.mysql.com)
Why Was Query Cache Removed?
The Query Cache was deprecated because of scalability and maintenance concerns, including contention under workloads with many concurrent queries.
MySQL 8.0 removed the Query Cache and its related settings, including query_cache_size, query_cache_type, and query_cache_limit. (dev.mysql.com)
What Should Modern MySQL Use Instead?
For current MySQL versions, do not attempt to configure query_cache_size.
Instead, improve database performance through techniques such as:
- Proper indexing
- Query optimization
- InnoDB buffer pool tuning
- Application-level caching
- Appropriate database design
Application caches such as Redis can also be considered when repeated data retrieval needs to be reduced.
Conclusion
query_cache_size was an important MySQL performance setting in older versions because it controlled memory used by the Query Cache.
Today, it should be treated as a legacy MySQL configuration option. Since the Query Cache was removed in MySQL 8.0, modern applications should focus on query optimization, indexing, InnoDB memory configuration, and application-level caching instead.