Introduction
The MySQL query cache was a feature that cached the result sets of identical SELECT statements, allowing subsequent identical queries to be served from memory rather than re-executing against the database. While this sounded beneficial, the query cache had significant limitations: it only helped with read-heavy workloads on static data, it introduced locking contention on write-heavy systems, and it became increasingly problematic as data sets grew.
In MySQL 5.7, the query cache was deprecated, and in MySQL 8.0, it was completely removed. Many applications and configurations still reference query cache settings (query_cache_type, query_cache_size, query_cache_limit), which now cause errors or warnings during MySQL startup or when upgrading from earlier versions. Understanding how to properly remove these settings and implement alternative caching strategies is essential for a smooth MySQL 8.0 migration.
The removal of the query cache was a deliberate design decision by the MySQL team. Modern workloads and hardware have evolved, and the query cache's architectural limitations outweighed its benefits for most use cases. The single mutex protecting the query cache became a bottleneck on multi-core systems, and the overhead of invalidating cache entries on every write operation was significant.
Symptoms
When upgrading to MySQL 8.0 with query cache configuration still present, you will encounter these symptoms:
- MySQL server fails to start with "unknown variable" errors
- Error messages in MySQL error log:
unknown variable 'query_cache_type=1'orunknown variable 'query_cache_size=64M' - Warnings about deprecated options during configuration validation
- Applications that relied on query cache behavior may show performance changes
- MySQL configuration validation tools report errors for query cache settings
- Configuration management tools fail when applying existing MySQL templates
SHOW VARIABLES LIKE 'query_cache%';returns empty results in MySQL 8.0
Common error messages in MySQL logs:
[ERROR] unknown variable 'query_cache_type=1'
[ERROR] unknown variable 'query_cache_size=64M'
[ERROR] unknown variable 'query_cache_limit=2M'
[ERROR] AbortingOr with mysqld --validate-config:
mysqld: [ERROR] Found unknown option '--query-cache-type=1' in configuration file.Common Causes
Several factors contribute to MySQL query cache deprecation issues:
- 1.Inherited configuration files: Configuration files from MySQL 5.7 or earlier versions that contain
query_cache_*settings are incompatible with MySQL 8.0. - 2.Third-party configuration templates: Many database configuration generators and templates still include query cache settings by default, not accounting for MySQL 8.0 changes.
- 3.Monitoring and tooling expectations: Some monitoring tools and scripts check for query cache metrics that no longer exist in MySQL 8.0, causing alerts or errors.
- 4.Documentation lag: Some guides and tutorials still recommend query cache settings for performance tuning, leading to confusion.
- 5.Configuration management drift: Puppet, Chef, Ansible, or other configuration management tools may still apply query cache settings from older module versions.
- 6.Application-level expectations: Applications might check for query cache status or attempt to enable/disable it programmatically.
- 7.Backup restoration: Restoring MySQL 5.7 configuration backups onto MySQL 8.0 servers introduces incompatible settings.
Step-by-Step Fix
Follow these steps to resolve MySQL query cache deprecation issues:
Step 1: Identify all query cache configuration references
Search for query cache settings across all configuration locations:
```bash # Check main MySQL configuration grep -r "query_cache" /etc/mysql/
# Check additional configuration directories grep -r "query_cache" /etc/my.cnf* 2>/dev/null grep -r "query_cache" /usr/etc/my.cnf* 2>/dev/null
# Check for command-line options in systemd service systemctl cat mysql 2>/dev/null | grep -i query_cache systemctl cat mysqld 2>/dev/null | grep -i query_cache
# Check for environment variable configurations grep -r "query_cache" /etc/default/mysql* 2>/dev/null grep -r "query_cache" /etc/sysconfig/mysql* 2>/dev/null ```
Step 2: Remove query cache settings from configuration files
Edit configuration files to remove or comment out query cache settings:
```bash # Backup current configuration sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.backup
# Edit the configuration file sudo nano /etc/mysql/my.cnf ```
Remove or comment out these lines:
# Comment out or remove these deprecated settings:
# query_cache_type = 1
# query_cache_size = 64M
# query_cache_limit = 2M
# query_cache_min_res_unit = 4K
# query_cache_wlock_invalidate = OFFAlternatively, use sed to remove them automatically:
# Remove query cache settings from all MySQL config files
sudo sed -i '/query_cache/d' /etc/mysql/my.cnf
sudo sed -i '/query_cache/d' /etc/mysql/mysql.conf.d/*.cnf
sudo sed -i '/query_cache/d' /etc/mysql/conf.d/*.cnfStep 3: Validate configuration before restarting
Always validate configuration before applying changes:
```bash # Validate configuration file syntax (MySQL 8.0+) mysqld --validate-config
# Or use this for earlier validation mysqld --help --verbose 2>&1 | grep -i error
# Check for any remaining unknown variables mysqld --print-defaults | grep -i query_cache ```
Step 4: Update configuration management tools
If using configuration management, update your playbooks/manifests:
For Ansible:
# Remove from templates
- name: Configure MySQL (MySQL 8.0 compatible)
template:
src: my.cnf.j2
dest: /etc/mysql/my.cnf
when: mysql_version is version('8.0', '>=')
# Remove query_cache settings from my.cnf.j2 templateFor Puppet:
# Remove query_cache_* parameters from mysql::server class
class { 'mysql::server':
# Do NOT include these for MySQL 8.0:
# query_cache_type => '1',
# query_cache_size => '64M',
override_options => {
'mysqld' => {
# MySQL 8.0 compatible options only
'max_connections' => '200',
'innodb_buffer_pool_size' => '1G',
}
}
}Step 5: Update monitoring and alerting
Remove checks for query cache metrics:
```sql -- This query returns empty in MySQL 8.0 SHOW STATUS LIKE 'Qcache%';
-- Instead, monitor these alternatives: SHOW STATUS LIKE 'Innodb_buffer_pool%'; SHOW STATUS LIKE 'Handler%'; SHOW STATUS LIKE 'Select%'; ```
Update monitoring scripts:
```bash # Old (MySQL 5.7) monitoring check - remove this # mysql -e "SHOW STATUS LIKE 'Qcache_hits'"
# New (MySQL 8.0) buffer pool monitoring mysql -e "SHOW STATUS LIKE 'Innodb_buffer_pool_read%'" ```
Step 6: Restart MySQL service
After configuration changes, restart MySQL:
```bash # Stop MySQL sudo systemctl stop mysql
# Start MySQL with validated configuration sudo systemctl start mysql
# Verify MySQL is running sudo systemctl status mysql
# Check error log for any issues sudo tail -f /var/log/mysql/error.log ```
Step 7: Verify query cache removal
Confirm query cache settings are gone:
```sql -- This should return empty result in MySQL 8.0 SHOW VARIABLES LIKE 'query_cache%';
-- Check MySQL version SELECT VERSION();
-- Verify server is running properly SHOW STATUS LIKE 'Uptime'; ```
Alternative Caching Strategies
Since MySQL 8.0 removed the query cache, implement these alternatives:
Option 1: Increase InnoDB Buffer Pool
[mysqld]
# Allocate 70-80% of available RAM for InnoDB buffer pool
innodb_buffer_pool_size = 4G
innodb_buffer_pool_instances = 4Option 2: Application-level caching
Implement caching in your application layer:
```python # Using Redis for query result caching import redis import json
cache = redis.Redis(host='localhost', port=6379, db=0)
def get_user(user_id): cache_key = f"user:{user_id}" cached = cache.get(cache_key)
if cached: return json.loads(cached)
# Query database result = db.execute(f"SELECT * FROM users WHERE id = {user_id}")
# Cache for 5 minutes cache.setex(cache_key, 300, json.dumps(result)) return result ```
Option 3: MySQL memcached plugin
```sql -- Install memcached plugin for InnoDB (if available) INSTALL PLUGIN daemon_memcached SONAME 'libmemcached.so';
-- Create container table CREATE TABLE test.memcached_test ( id VARCHAR(32) NOT NULL, value VARCHAR(1024) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB; ```
Verification
After removing query cache settings and implementing alternatives:
```bash # Verify MySQL is running without errors sudo systemctl status mysql
# Check error log for startup success sudo grep -i "ready for connections" /var/log/mysql/error.log
# Monitor buffer pool hit rate mysql -e "SHOW STATUS LIKE 'Innodb_buffer_pool_read%';" | \ awk 'NR>1 {reads+=$2} END {print "Buffer pool hit rate:", reads}'
# Check for any remaining configuration warnings mysqld --validate-config && echo "Configuration valid" ```
Prevention
To prevent query cache issues in future MySQL environments:
- 1.Version-aware configuration management: Use conditional logic in configuration management tools to apply different settings based on MySQL version.
- 2.Configuration testing in CI: Include MySQL configuration validation in your CI/CD pipeline before deploying to production.
- 3.Keep documentation updated: Maintain version-specific documentation for MySQL configuration, clearly marking deprecated options.
- 4.Use official MySQL Docker images: When containerizing, use official MySQL 8.0 images that don't include query cache settings.
- 5.Monitor deprecation notices: Watch MySQL release notes for deprecated features to prepare for future removals.
- 6.Implement external caching early: Don't rely on built-in query cache. Implement Redis, Memcached, or application-level caching as part of your architecture.
Related Articles
- [Database troubleshooting: Fix Backup Exclusive Lock Table Production Writes ](backup-exclusive-lock-table-production-writes)
- [Fix Connection Pool Leak Application Not Closing Issue in Database](connection-pool-leak-application-not-closing)
- [Fix Connection Reset Idle Timeout Firewall Issue in Database](connection-reset-idle-timeout-firewall)
- [Fix Connection Reset Idle Timeout Serverless Database Issue in Database](connection-reset-idle-timeout-serverless-database)
- [Fix Connection String Encoding Special Characters Issue in Database](connection-string-encoding-special-characters)
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "MySQL Query Cache Deprecated Issues", "description": "Resolve MySQL query cache deprecation issues when migrating to MySQL 8.0, remove deprecated configuration options, and implement alternative caching strategies.", "url": "https://www.fixwikihub.com/fix-mysql-query-cache-deprecated-issues", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2026-01-23T19:29:05.776Z", "dateModified": "2026-01-23T19:29:05.776Z" } </script>