简体   繁体   English

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

[英]java.sql.SQLException: Unknown system variable 'query_cache_size'

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版本

query_cache_size was removed in MySQL 8. Check the docs . query_cache_size在MySQL辗转8.检查文档

It works with JDBC driver 5.1.44.它适用于 JDBC 驱动程序 5.1.44。

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!!!!它有效!!!!

I had a similar problem.我有一个类似的问题。 I resolved it by specifying the version in 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.对我来说就像一种魅力。

Try using MySQL 8.0.3 As can be seen on the docs, the query_cache_size was removed on MySQL8.尝试使用 MySQL 8.0.3 从文档中可以看出,MySQL8 上删除了 query_cache_size。 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. JetBrains 的人遇到了同样的问题,似乎是通过将驱动程序更新到 MySQL JDBC 驱动程序 v 5.1.44 版本来修复它。

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

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

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. 1) 使用确切的 mysql-connector-java jar 或依赖项作为您的 mysql 版本。
2) if your mysql version is 8 or 6+ try to use this "com.mysql.cj.jdbc.Driver" driver class. 2) 如果您的 mysql 版本是 8 或 6+,请尝试使用此“com.mysql.cj.jdbc.Driver”驱动程序类。

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

This exception is related to pom.xml dependency.此异常与 pom.xml 依赖项有关。 When I use below dependency in pox.xml:当我在 pox.xml 中使用以下依赖项时:

 <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>6.0.5</version>
 </dependency>

It shows exception:Caused by: java.sql.SQLException: Unknown system variable query_cache_size它显示异常:Caused by: java.sql.SQLException: Unknown system variable query_cache_size

But, when I use below dependency:但是,当我使用以下依赖项时:

  <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.13</version>
  </dependency>

It works.You have to use latest dependency它有效。您必须使用最新的依赖项

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

<version>8.0.11</version>

Use Below mention dependency it will work for you!使用下面提到的依赖,它会为你工作!

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.16</version>
    </dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM