[Solved] java.sql.SQLException: Unknown system variable cache query size

Recently, when I was learning springboot + MySQL + mybatis and doing a project with CSDN boss, I encountered an error when connecting to MySQL:

java.sql.SQLException: Unknown system variable 'query_cache_size'

Error reason:
the version of MySQL connector Java is too low, and the database driver version does not match the local MySQL version. Query cache has been out of date since MySQL 5.7.20, but it has been removed since MySQL 8.0
solution:
first, modify the driver name in the application. YML or application. Properties file

driver-class-name: com.mysql.cj.jdbc.Driver  #Linked Drivers for MySQL 8.0 onwards
com.mysql.jdbc.Driver #Older linked drivers

Then modify the driver version in the POM. XML file

<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>8.0.25</version>
			<scope>runtime</scope>
		</dependency>

The previous version here is 5. X. just change it to the actual MySQL version number. Mine is 8.0.25
remember to reload Maven’s dependencies after changing. Otherwise, it will still report an error:

Cannot load driver class:com.mysql.cj.jdbc.Driver

Click this icon to reload the dependency

perfect solution!

Read More: