Article Directory
Preface
Recently, when using the mybatis-generator
database reverse generation tool, the following error occurred, namely java.sql.SQLException: Unknown system variable 'query_cache_size'
.
1. Reason analysis
- Check that the connected database version is
8.0.20
- The JDBC driver
mysql-connector-java
version used by the project is5.1.41
- Query related documents on MYSQL official website
Official website statement:
The query cache is deprecated as of MySQL 5.7.20,
and is removed in MySQL 8.0. Deprecation includes query_cache_size.
query cache 在MySQL 5.7.20 已经过时了,并且在MySQL 8.0 版本中被移除了。
Obviously, it is caused by the inconsistency between the database driver and the database version.
Two, version correspondence table
The following table summarizes the correspondence between mysql-connector-java and JDBC, MySQL, JRE, and JDK versions.
Three, the solution
2.1 Introduce a higher version of the driver
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
2.2 Modify connection configuration information
spring:
datasource: # 数据源的相关配置
driver-class-name: com.mysql.cj.jdbc.Driver #从com.mysql.jdbc.Driver修改为com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/shop?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=UTC
Or it is also possible to introduce version 5.1.49, so there is no need to modify the connection configuration information:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
spring:
datasource: # 数据源的相关配置
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/shop?&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true