简体   繁体   English

使用 spring R2DBC 连接 mySQL 服务器版本 8 时出现未知的系统变量“tx_isolation”

[英]Unknown system variable 'tx_isolation' when using spring R2DBC to connect with a mySQL server version 8

I created a new spring boot project using the IntelliJ Idea's spring initializer and checked the Web/Spring reactive Web and the SQL/Spring data R2DBC dependencies.我使用 IntelliJ Idea 的 spring 初始值设定项创建了一个新的 spring boot 项目,并检查了Web/Spring reactive WebSQL/Spring data R2DBC依赖项。

I also added the the dependency to the R2DBC implementation for MySQL我还为 MySQL 添加了对 R2DBC 实现的依赖

        <dependency>
            <groupId>dev.miku</groupId>
            <artifactId>r2dbc-mysql</artifactId>
            <version>0.8.2.RELEASE</version>
        </dependency>

and the java connector和 java 连接器

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

Asking the version of the MySQL server from a console with select version();使用select version();从控制台询问 MySQL 服务器的select version(); I get 8.0.17我得到8.0.17

The connection factory configuration is like this:连接工厂配置是这样的:

@Configuration
@RequiredArgsConstructor
public class R2dbcConfig extends AbstractR2dbcConfiguration {

    @Bean
    public ConnectionFactory connectionFactory() {
        ConnectionFactoryOptions conf = ConnectionFactoryOptions.builder()
                .option(DRIVER, "mysql")
                .option(HOST, "the.db.url")
                .option(PORT, 33066612)
                .option(USER, "myUserName")
                .option(PASSWORD, "myPassword")
                .option(DATABASE, "aDbName")
                .build();
        return ConnectionFactories.find(conf);
    }
}

Nevertheless, when I run the application I get the following exception然而,当我运行应用程序时,我收到以下异常

reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.dao.DataAccessResourceFailureException: Failed to obtain R2DBC Connection; nested exception is io.r2dbc.spi.R2dbcNonTransientResourceException: [1193] Unknown system variable 'tx_isolation'
Caused by: org.springframework.dao.DataAccessResourceFailureException: Failed to obtain R2DBC Connection; nested exception is io.r2dbc.spi.R2dbcNonTransientResourceException: [1193] Unknown system variable 'tx_isolation'

Answers to similar questions instructed the asker to update the version of the mysql:mysql-connector-java to 8.+ , and according to IntelliJ the versión resolved by maven is 8.0.26 .对类似问题的回答指示提问者将mysql:mysql-connector-java的版本更新为8.+ ,并且根据 IntelliJ,maven 解决的版本是8.0.26 Curiously, if I remove the connector dependency the result is exactly the same.奇怪的是,如果我删除连接器依赖项,结果是完全一样的。

So, I debbuged the R2DBC implementation to find out what is happening and I discovered that during the handshake, the dev.miku.r2dbc.mysq.QueryFlow#initHandshake method receives a HandshakeRequest message whose headers tell that the server version is "5.5.30".所以,我调试了 R2DBC 实现以找出发生了什么,我发现在握手期间, dev.miku.r2dbc.mysq.QueryFlow#initHandshake方法收到一个HandshakeRequest消息,其标头表明服务器版本是“5.5.30 ”。 And that causes the R2DBC implementation to use the old "tx_isolation" system variable name instead of the new "transaction_isolation".这会导致 R2DBC 实现使用旧的“tx_isolation”系统变量名称而不是新的“transaction_isolation”。

Why?为什么? What am I missing?我错过了什么?

https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html says: https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html说:

The tx_isolation and tx_read_only system variables have been removed. tx_isolationtx_read_only系统变量已被删除。 Use transaction_isolation and transaction_read_only instead.请改用transaction_isolationtransaction_read_only

You checked and discovered the server version is 8.0.17.您检查并发现服务器版本是 8.0.17。 This is more authoritative than the handshake headers message.这比握手标头消息更权威。

I recommend searching your classpath for any leftover jar files with old versions of the connector.我建议使用旧版本的连接器在您的类路径中搜索任何剩余的 jar 文件。 You may have both version 8.0.26 of the connector and an older version that hasn't been updated to use the new option names.您可能同时拥有 8.0.26 版本的连接器和尚未更新为使用新选项名称的旧版本。

Could you solved it?你能解决吗? I found that R2dbc mysql driver doesn't get my MySql version, because it has a check of it to ask for tx_isolation or transaction_isolation.我发现 R2dbc mysql 驱动程序没有得到我的 MySql 版本,因为它检查了它以请求 tx_isolation 或 transaction_isolation。

The solution I got was changing the driver to Jasync.我得到的解决方案是将驱动程序更改为 Jasync。

//DB
implementation("com.github.jasync-sql:jasync-r2dbc-mysql:2.0.4")
implementation("io.r2dbc:r2dbc-h2")
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc:2.6.0")

And my config:还有我的配置:

@Configuration
@EnableTransactionManagement
@EnableConfigurationProperties(DbPropertiesConfig::class)
class DataSourceConfiguration {
@Configuration
    class ProdMySQLConfiguration(@Autowired val dbPropertiesConfig: DbPropertiesConfig) : AbstractR2dbcConfiguration() {

        @Bean
        @Throws(FuryDecryptException::class, FuryUpdateException::class, FuryNotFoundAPPException::class)
        override fun connectionFactory(): ConnectionFactory =
                JasyncConnectionFactory(MySQLConnectionFactory(
                        com.github.jasync.sql.db.Configuration(
                                database = dbPropertiesConfig.db,
                                port = dbPropertiesConfig.port,
                                username = dbPropertiesConfig.username,
                                host = dbPropertiesConfig.host,
                                password = dbPropertiesConfig.password
                        )
                ))
    }

} }

Taking into consideration I have that DbPropertiesConfig in my yml.考虑到我的 yml 中有 DbPropertiesConfig。

Doc/Example: Doc Example文档/示例:文档示例

Gitter: https://gitter.im/jasync-sql/support Gitter: https : //gitter.im/jasync-sql/support

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

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