java.sql.SQLException Unknown system variable 'query_cache_size'
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
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:

