JDBC/MYSQL問題 : Unknown system variable 'query_cache_size'
背景
今天執行一個開源專案,竟然遇到Caused by: java.sql.SQLException: Unknown system variable 'query_cache_size'
的問題。真是神奇,query_cache_size
是什麼,如何解決?
>>>
先看詳細報錯資訊:
#by zhengkai.blog.csdn.net
2019-09-08 22:20:09.821 ERROR 9400 --- [eate-1098645181] c.a.d.p.DruidDataSource : create connection SQLException, url: jdbc:mysql://localhost:3306/mcms?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true, errorCode 0, state 08001
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_222]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_222]
at sun.reflect.DelegatingConstructorAccessorImpl.__newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_222]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45009) ~[?:1.8.0_222]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45012) ~[?:1.8.0_222]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_222]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.Util.getInstance(Util.java:387) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2163) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2088) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_222]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_222]
at sun.reflect.DelegatingConstructorAccessorImpl.__newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_222]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45009) ~[?:1.8.0_222]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45012) ~[?:1.8.0_222]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_222]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:149) ~[druid-1.1.9.jar:1.1.9]
at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218) ~[druid-1.1.9.jar:1.1.9]
at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:143) ~[druid-1.1.9.jar:1.1.9]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1515) ~[druid-1.1.9.jar:1.1.9]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1578) ~[druid-1.1.9.jar:1.1.9]
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2466) [druid-1.1.9.jar:1.1.9]
Caused by: java.sql.SQLException: Unknown system variable 'query_cache_size'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3833) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3283) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2126) ~[mysql-connector-java-5.1.39.jar:5.1.39]
... 18 more
Reason
原因是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
在MySQL5.7.20
就已經過時了,而在MySQL8.0之後就已經被真正移除了。所以必須用新版的jdbc-mysql連線庫來與新版的mysql8.0匹配
Solution
既然mysql-connecter-java的版本過低,找個8.x的版本就可以了,建議是和資料庫版本相對應,例如phpStudy是8.0.12
,那麼jdbc用8.0.12
即可(更新版本也是ok的)。
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.12</version>
</dependency>
>>>
更多版本詳情可以在以下地址檢視:
https://mvnrepository.com/artifact/mysql/mysql-connector-java
相關文章
- mysql 動態引數(Dynamic System Variable Summary)MySql
- 記錄錯誤: *Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘spec_templaMySqlJDBCExceptionError
- Unknown column ‘name‘ in ‘field list‘ ; bad SQL grammar []; nested exception is com.mysql.jdbc.excepExceptionMySqlJDBC
- 解決driverClassName: com.mysql.cj.jdbc.Driver報紅問題MySqlJDBC
- sql mysql variable autocommit (5)MySqlMIT
- mysql Unknown error 1054MySqlError
- 問題解決local variable 'xxx' referenced before assignment
- MySQL JDBC常用知識,封裝工具類,時區問題配置,SQL隱碼攻擊問題MySqlJDBC封裝
- 解決Mybatis連線Sql server 出現 Cannot load JDBC driver class 'com.mysql.jdbc.Driver '的問題MyBatisServerJDBCMySql
- JDBC Oracle executeUpdate 卡死問題解決JDBCOracle
- servlet 呼叫jdbc 出現得問題ServletJDBC
- mysql關於variable的總結MySql
- MySQL 中出現報錯提示: ‘Variable ‘XXX‘ is a read only variable‘的解決方法MySql
- 解決問題:Variable 'time_zone' can't be set to the value of 'NULL'Null
- mysql遇到Variable can’t be set to the value of ‘NULL’MySqlNull
- Mysql入門【JDBC】MySqlJDBC
- JDBC連線mysqlJDBCMySql
- MySQL 問題MySql
- JMeter連線mysql資料庫之connector包匹配問題(Cannot create PoolableConnectionFactory (Unknown initial character set index...)JMeterMySql資料庫Index
- MySQL:ERROR 1286 (42000): Unknown storage engine 'MyISAM'MySqlError
- mysql Unknown column ‘‘ in ‘field list‘解決方案MySql
- MySQL的JDBC下載MySqlJDBC
- Java JDBC連線MYsqlJavaJDBCMySql
- 解決問題: go get certificate signed by unknown authority 換個代理或者Go
- 解決nginx: [emerg] unknown directive “stream“ in /etc/nginx/nginx.conf問題Nginx
- mysql 1130 問題MySql
- Spring Boot入門(五):使用JDBC訪問MySql資料庫Spring BootJDBCMySql資料庫
- JDBC用ResultSet訪問大量資料時會遇到的問題JDBC
- 使用System.IO.File.Create()時注意的問題
- Mysql:Variable 'XXXt' can't be set to the value of 'NULL'解決MySqlNull
- JDBC for MySQL 最新jar包下載JDBCMySqlJAR
- springboot: kotlin + gradle + jdbc(mysql) demoSpring BootKotlinGradleJDBCMySql
- mysql 轉義問題MySql
- mysql 遇到的問題MySql
- Mysql:常見問題MySql
- MySQL死鎖問題MySql
- 解決Charles手機抓包出現unknown和亂碼的問題
- 2020-10-10: 傳統JDBC開發存在的問題?JDBC