天天看點

Unknown system variable 'query_cache_size'

java連接配接mysql 報錯

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

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:545)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:115)

at com.mysql.cj.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:1983)

at com.mysql.cj.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:1936)

at com.mysql.cj.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)

at com.mysql.cj.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:2831)

at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:2381)

at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1739)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1596)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:633)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:347)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:219)

at java.sql.DriverManager.getConnection(DriverManager.java:664)

at java.sql.DriverManager.getConnection(DriverManager.java:270)

原因是mysql-connector-java的版本還是6.0.6,需要更新版本到8.0.11 ,這個報錯就不存在了

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>8.0.11</version>

</dependency>

此方法同樣适用于gradle