mysql Statement violates GTID consistency 的坑

Posted SheaChen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql Statement violates GTID consistency 的坑相关的知识,希望对你有一定的参考价值。

今天项目迁移,重新换了一个数据库版本,然后问题来了,原本运行正常的程序迁移过来之后就是不能正常运行,后台报错如下:

update tbl_user_info set -- 强制下架 mv_count = mv_count-1, update_time=now() where user_id = ?; update tbl_user_info a,tbl_mv_like b set a.enjoy_num = a.enjoy_num -1, a.update_time = now() where b.mvlikeId = ? and b.userId =a.user_id and b.userId != ? and b.isLIke = 1 and b.state = 0
### Cause: java.sql.SQLException: Statement violates GTID consistency: Updates to non-transactional tables can only be done in either autocommitted statements or single-statement transactions, and never in the same statement as updates to transactional tables.
; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1785]; Statement violates GTID consistency: Updates to non-transactional tables can only be done in either autocommitted statements or single-statement transactions, and never in the same statement as updates to transactional tables.; nested exception is java.sql.SQLException: Statement violates GTID consistency: Updates to non-transactional tables can only be done in either autocommitted statements or single-statement transactions, and never in the same statement as updates to transactional tables.

网上查了一下 Statement violates GTID consistency这个,然后看到这个网页https://dev.mysql.com/doc/refman/5.6/en/replication-options-gtids.html,一开始还以为是数据库模式的问题,后面看了下数据库表,才知道原来是运维人员在新的数据库上把我的数据库表的模式设置成了MyISAM这个模式,然后去数据库show engines了一下,

可以看到,这个模式是不支持事物的,将它修改为InnoDB,问题搞定

事实上后面我又试了mysql5.7以上的版本,同样将引擎修改为MyISAM,执行操作,显示执行成功。到这儿我真的不知道究竟什么情况了,但确实是我让运维的同事将我的表的引擎修改为InnoDB就执行成功了。所以如果你也遇到同样的问题,不防检查一下表的引擎,修改一下试试

以上是关于mysql Statement violates GTID consistency 的坑的主要内容,如果未能解决你的问题,请参考以下文章

如何计算一个项目在mysql中给定日期出现的次数

SQLSTATE[42000]: Syntax error or access violation

mysql创建statement对象

MySQL: LEAVE Statement

MYSQL 之 JDBC: 增删改查通过Statement执行更新操作

Case Statement 总是给出 1. MySQL