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登陸報錯mysql: unknown variable 'basedir=MySql
- ERROR 1193: Unknown system variable 'log_slow_queries'Error
- mysql 動態引數(Dynamic System Variable Summary)MySql
- jdbc連線mysql問題-helpJDBCMySql
- JDBC連線MySQL失效的問題JDBCMySql
- 因login-path導致MySQL 啟動[ERROR]unknown variable 'password=*****'MySqlError
- 解決jdbc不能重連mysql的問題JDBCMySql
- mysql 匯入問題:Unknown command '\'' 解決辦法MySql
- 記錄錯誤: *Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘spec_templaMySqlJDBCExceptionError
- JDBC問題,求助JDBC
- unknown variable 'defaults-file=/home/mysql/my3310.cnf'--percona server 5.7MySqlServer
- MYSQL5.5修改字符集報錯:unknown variable 'default-character-set=utf8'MySql
- mysqlbinlog: unknown variable 'default-character-set=utf8'MySql
- MySQL JDBC row_count()數字不準確的問題MySqlJDBC
- 解決driverClassName: com.mysql.cj.jdbc.Driver報紅問題MySqlJDBC
- JDBC連線ORACLE問題JDBCOracle
- Unknown column ‘name‘ in ‘field list‘ ; bad SQL grammar []; nested exception is com.mysql.jdbc.excepExceptionMySqlJDBC
- MySQL 報錯'Variable 'XXX' is a read only variable'MySql
- JDBC中事務的問題JDBC
- BMP的JDBC問題,請指教JDBC
- jdbc資源的回收問題!JDBC
- 【Ubuntu】unknown host問題解決辦法Ubuntu
- oracle taf unknown 問題處理過程Oracle
- MySQL JDBC常用知識,封裝工具類,時區問題配置,SQL隱碼攻擊問題MySqlJDBC封裝
- sql mysql variable autocommit (5)MySqlMIT
- SELECT INTO FROM mysql Undeclared variableMySql
- Docker 容器中“TERM environment variable not set.”問題解決Docker
- JDBC Oracle executeUpdate 卡死問題解決JDBCOracle
- servlet 呼叫jdbc 出現得問題ServletJDBC
- 【Fenng 】JDBC 的 setTimestamp 效能問題JDBC
- 解決Mybatis連線Sql server 出現 Cannot load JDBC driver class 'com.mysql.jdbc.Driver '的問題MyBatisServerJDBCMySql
- mysql Unknown error 1054MySqlError
- mysql關於variable的總結MySql
- MySQL大小寫敏感問題lower_case_table_names & lower_case_file_systemMySql
- Spark JDBC To MySQLSparkJDBCMySql
- JDBC-MySqlJDBCMySql
- 請問一個有關jdbc效能的問題JDBC
- 解決crs_stat狀態為UNKNOWN問題