mysql 1786_使用flyway控制数据库版本时启动发生1786错误的解决方案

近日在spring-boot:2.2.2.release中启用了flyway。但在生产环境中启动却发生了如下错误:DB: Statement violates GTID consistency: CREATE TABLE ... SELECT. (SQL State: HY000 - Error Code: 1786)

查看日志获得详细信息如下:

-----------------

SQL State : HY000

Error Code : 1786

Message : Statement violates GTID consistency: CREATE TABLE ... SELECT.

Location : ()

Line : 1

Statement : CREATE TABLE `task`.`flyway_schema_history` (

`installed_rank` INT NOT NULL,

`version` VARCHAR(50),

`description` VARCHAR(200) NOT NULL,

`type` VARCHAR(20) NOT NULL,

`script` VARCHAR(1000) NOT NULL,

`checksum` INT,

`installed_by` VARCHAR(100) NOT NULL,

`installed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

`execution_time` INT NOT NULL,

`success` BOOL NOT NULL,

CONSTRAINT `flyway_schema_history_pk` PRIMARY KEY (`installed_rank`)

) ENGINE=InnoDB AS SELECT 1 as "installed_rank", '1.0.0' as "version", '<< Flyway Baseline >>' as "description", 'BASELINE' as "type", '<< Flyway Baseline >>' as "script", NULL as "checksum", 'task' as "installed_by", CURRENT_TIMESTAMP as "installed_on", 0 as "execution_time", TRUE as "success"

根据以上日志获知:flyway在初始化其依赖的flyway_schema_history表时发生了1786错误。查阅相文资料获知:mysql认为create table xxx as select存在一定的风险,所以默认禁止用户这么做。

问题原因猜出来后,解决的方法也就有了。方案有二:

一、将mysql的相关安全设置关闭,即--enforce-gtid-consistency=false。

二、手动指定flyway的版本(经测试5.2.4版本并不存在该问题)

笔者选用的第二种。

org.flywaydb

flyway-core

5.2.4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值