java.sql.SQLException: 未知的系统变量 'query_cache_size'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49984267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 03:10:47  来源:igfitidea点击:

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

javamysqlspring-bootjdbc

提问by Kiên Tr?n Trung

I have a app running with JDBC and get data from MySQL, but I can't build it because of this error :

我有一个使用 JDBC 运行的应用程序并从 MySQL 获取数据,但由于此错误我无法构建它:

java.sql.SQLException: Unknown system variable 'query_cache_size'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2497) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2455) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3777) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3240) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2249) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2035) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_131]

I have file application.properties here

我这里有文件 application.properties

#specs.dir=/specs/
#
#################### Spring Boot Data Source Configuration ############
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#spring.datasource.url=jdbc:mysql://localhost:3306/savingbooking?useSSL=false
#spring.datasource.username=root
#spring.datasource.password=ZAQ!2wsx
#spring.datasource.initialize=true
#spring.jpa.hibernate.ddl-auto=update
#spring.jpa.properties.hibernate.format_sql=true
#spring.jpa.show-sql=true
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect

Mysql workbench is 8.0 version

Mysql工作台是8.0版本

采纳答案by steven35

query_cache_sizewas removed in MySQL 8. Check the docs.

query_cache_size已在 MySQL 8 中删除。检查文档

It works with JDBC driver 5.1.44.

它适用于 JDBC 驱动程序 5.1.44。

回答by ISHAN KUMAR GHOSH

Try using MySQL 8.0.3 As can be seen on the docs, the query_cache_size was removed on MySQL8. JetBrains guys have suffered the same issue, is seems to be that it is fixed by updating the driver to the version MySQL JDBC driver v 5.1.44.

尝试使用 MySQL 8.0.3 从文档中可以看出,MySQL8 上删除了 query_cache_size。JetBrains 的人遇到了同样的问题,似乎是通过将驱动程序更新到 MySQL JDBC 驱动程序 v 5.1.44 版本来修复它。

回答by vineeth sharma

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

java.sql.SQLException: 未知的系统变量 'query_cache_size'

In pom file of your project, just update the version of the dependency.

在项目的 pom 文件中,只需更新依赖项的版本。

For example it's 6.0.2 of mysql java connector just update it to latest one like 8.0.11

例如,它是 6.0.2 的 mysql java 连接器,只需将其更新为最新版本,例如 8.0.11

It works!!!!

有用!!!!

回答by Asad Shakeel

I had a similar problem. I resolved it by specifying the versionin mysql dependency

我有一个类似的问题。我通过在 mysql 依赖项中指定版本来解决它

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

Worked like a charm for me.

对我来说就像一种魅力。

回答by ??ng Ng?c Phong

If you using MySql v8.0 then you should try fix this bug with

如果您使用 MySql v8.0,那么您应该尝试使用以下命令修复此错误

mysql-connector-java-5.1.9

mysql-connector-java-5.1.9

回答by Mukesh Kumar yadav

I stuck on this issue, spend full one day and finally i got solution.

我坚持这个问题,花了整整一天的时间,最后我得到了解决方案。

Solution :

解决方案 :

1) Use exact mysql-connector-java jar or dependency as your mysql version.
2) if your mysql version is 8 or 6+ try to use this "com.mysql.cj.jdbc.Driver" driver class.

1) 使用确切的 mysql-connector-java jar 或依赖项作为您的 mysql 版本。
2) 如果您的 mysql 版本是 8 或 6+,请尝试使用此“com.mysql.cj.jdbc.Driver”驱动程序类。

回答by Ooguro

Ok so what I did as metioned above. I just added the mysql-connector-java-5.1.4 to build path and ran the project on my server and connected fine to mysql

好的,我按照上面提到的做了什么。我刚刚添加了 mysql-connector-java-5.1.4 来构建路径并在我的服务器上运行该项目并连接到 mysql

回答by Shubham

just change the version of mysql use this in pom.xml

只需更改 mysql 的版本在 pom.xml 中使用它

<version>8.0.11</version>

回答by Enrique Jiménez Flores

For mysql 8:

对于 mysql 8:

mysql-connector-java-8.0.17.jar (or above) + db.driver=com.mysql.cj.jdbc.Driver instead of com.mysql.jdbc.Driver

mysql-connector-java-8.0.17.jar(或更高版本)+ db.driver=com.mysql.cj.jdbc.Driver 而不是 com.mysql.jdbc.Driver