今天項目遷移,重新換了一個數據庫版本,然后問題來了,原本運行正常的程序遷移過來之后就是不能正常運行,后台報錯如下:
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就執行成功了。所以如果你也遇到同樣的問題,不防檢查一下表的引擎,修改一下試試