java.sql.SQLException:目标:commerce.0.primary:vttablet:rpc 错误:代码 = InvalidArgument desc = 未知系统变量 'quer

Posted

技术标签:

【中文标题】java.sql.SQLException:目标:commerce.0.primary:vttablet:rpc 错误:代码 = InvalidArgument desc = 未知系统变量 \'query_cache_size\'【英文标题】:java.sql.SQLException: target: commerce.0.primary: vttablet: rpc error: code = InvalidArgument desc = Unknown system variable 'query_cache_size'java.sql.SQLException:目标:commerce.0.primary:vttablet:rpc 错误:代码 = InvalidArgument desc = 未知系统变量 'query_cache_size' 【发布时间】:2022-01-11 00:13:00 【问题描述】:

我在连接到 Vitess 的 mysql 集群时遇到了这个问题。以下是我正在使用的配置和版本。

Vitess - 12.0.0 MySQL - 8.0.27 mysql-connector-java - 8.0.27 Springboot - 2.6.1 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

请帮忙!

2021-12-05 18:01:52.833  INFO 16196 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-12-05 18:01:52.876  INFO 16196 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 35 ms. Found 1 JPA repository interfaces.
2021-12-05 18:01:53.445  INFO 16196 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-12-05 18:01:53.453  INFO 16196 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-12-05 18:01:53.454  INFO 16196 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.55]
2021-12-05 18:01:53.504  INFO 16196 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-12-05 18:01:53.504  INFO 16196 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1261 ms
2021-12-05 18:01:53.936  INFO 16196 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-12-05 18:01:53.975  INFO 16196 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.6.1.Final
2021-12-05 18:01:54.062  INFO 16196 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations 5.1.2.Final
2021-12-05 18:01:54.330  WARN 16196 --- [           main] o.h.e.j.e.i.JdbcEnvironmentInitiator     : HHH000342: Could not obtain connection to query metadata

java.sql.SQLException: target: commerce.0.primary: vttablet: rpc error: code = InvalidArgument desc = Unknown system variable 'query_cache_size' (errno 1193) (sqlstate HY000) (CallerID: userData1): Sql: "/* mysql-connector-java-8.0.27 (Revision: e920b979015ae7117d60d72bcc8f077a839cd791) */select @@session.auto_increment_increment as auto_increment_increment, @@character_set_client as character_set_client, @@character_set_connection as character_set_connection, @@character_set_results as character_set_results, @@character_set_server as character_set_server, @@collation_server as collation_server, @@collation_connection as collation_connection, @@init_connect as init_connect, @@interactive_timeout as interactive_timeout, @@license as license, @@lower_case_table_names as lower_case_table_names, @@max_allowed_packet as max_allowed_packet, @@net_write_timeout as net_write_timeout, @@performance_schema as performance_schema, @@query_cache_size as query_cache_size, @@query_cache_type as query_cache_type, @@sql_mode as sql_mode, @@system_time_zone as system_time_zone, @@time_zone as time_zone, @@tx_isolation as transaction_isolation, @@wait_timeout as wait_timeout from dual", BindVars: 
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.27.jar:8.0.27]
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.27.jar:8.0.27]
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828) ~[mysql-connector-java-8.0.27.jar:8.0.27]
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448) ~[mysql-connector-java-8.0.27.jar:8.0.27]
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241) ~[mysql-connector-java-8.0.27.jar:8.0.27]
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-java-8.0.27.jar:8.0.27]
    at org.springframework.jdbc.datasource.SimpleDriverDataSource.getConnectionFromDriver(SimpleDriverDataSource.java:144) ~[spring-jdbc-5.3.13.jar:5.3.13]
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:205) ~[spring-jdbc-5.3.13.jar:5.3.13]
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169) ~[spring-jdbc-5.3.13.jar:5.3.13]
    at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.6.1.Final.jar:5.6.1.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181) ~[hibernate-core-5.6.1.Final.jar:5.6.1.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) [hibernate-core-5.6.1.Final.jar:5.6.1.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) [hibernate-core-5.6.1.Final.jar:5.6.1.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) [hibernate-core-5.6.1.Final.jar:5.6.1.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) [hibernate-core-5.6.1.Final.jar:5.6.1.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) [hibernate-core-5.6.1.Final.jar:5.6.1.Final]
    

【问题讨论】:

【参考方案1】:

问题在于 MySQL 8.0 删除了查询缓存和相关变量,但 Vitess vtgate 仍然向客户端宣传它是 MySQL 5.5 服务器。 MySQL JDBC 连接器错误地认为它可以发送对已弃用变量的查询。

https://github.com/vitessio/vitess/issues/5205

解决方法:使用vtgate -mysql_server_version 通告 mysql 8.x 版本字符串(例如“8.0.17 源分发”)

【讨论】:

以上是关于java.sql.SQLException:目标:commerce.0.primary:vttablet:rpc 错误:代码 = InvalidArgument desc = 未知系统变量 'quer的主要内容,如果未能解决你的问题,请参考以下文章

java.sql.SQLException:getShort() 的值无效 - ''

java.sql.SQLException: SQL 语句在 org.hsqldb.jdbc.JDBCUtil.sqlException 处关闭

Oracle DB:java.sql.SQLException:关闭连接

Cause: java.sql.SQLException: 请求的转换无效 ; uncategorized SQLException for SQL []; SQL state [99999]; er

java.sql.SQLException: ORA-00604: 递归 SQL 级别 1 发生错误

Java:Sqlexception:位置不支持的 SQL92 令牌:178