java.sql.SQLException Unknown system variable 'query_cache_size'
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Understanding java.sql.SQLException: Unknown system variable 'query_cache_size'
While developing or maintaining applications that interact with databases using Java, encountering SQL exceptions is fairly common. One such exception is `java.sql.SQLException: Unknown system variable 'query_cache_size'`. This exception often indicates issues related to the configuration or version compatibility of the MySQL database server. Let's delve into the potential causes, implications, and solutions for this exception.
What is `query_cache_size`?
`query_cache_size` is a system variable in MySQL that specifies the amount of memory allocated for caching query results. The query cache can improve performance by storing the results of queries. When the same query is run again, the results can be retrieved from the cache rather than re-executing the query, reducing response time.
Root Cause of the Exception
The exception `java.sql.SQLException: Unknown system variable 'query_cache_size'` typically arises from the following scenarios:
- Deprecated Variable: As of MySQL 8.0, the `query_cache_size` system variable has been deprecated and removed. If your application tries to access or modify this variable on a MySQL 8.0 server, you'll encounter this exception.
- Configuration Error: Attempting to set or query the `query_cache_size` on a server version that doesn't support it, due to mistaken configuration files or scripts.
- Version Mismatch: Using JDBC drivers or SQL scripts that are incompatible with the MySQL server version.
Implications of the Exception
Encountering this exception might indicate:
- Legacy Code: The application may rely on deprecated features, suggesting a need for code updates or refactoring.
- Compatibility Issues: The database configuration or client application might not be aligned with the server's capabilities.
- Operational Bottlenecks: If part of your application's performance depended on cached queries, removal of this feature necessitates alternative solutions.
Addressing the Exception
Here are the steps you can take to resolve the exception:
- Check MySQL Version: Identify the version of MySQL server you are running. You can do this by executing:
Related reading
- java.util.Date vs java.sql.Date
- javax.transaction.Transactional vs org.springframework.transaction.annotation.Transactional
- Job for mysqld.service failed See systemctl status mysqld.service
- Join between tables in two different databases?
- java.util.Date to XMLGregorianCalendar
- java.util.Objects.isNull vs object null
- Join on foreign key in Kafka stream
- JOIN queries vs multiple queries

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.