uncategorized SQLException for SQL错误解决

今天搬砖的时候后台报了一个错误,但是我检查了一遍代码没有发现任何错误。

错误信息如下:

StatementCallback; uncategorized SQLException for SQL [delete from tablename where id = 1]; 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.

经过排除,发现进行批量更新的表其中有一个表的引擎是用的MyISAM,估计是当初设计表的时候弄错了。

平时开发时,大部分的情况下对数据进行更新操作都需要用到事务,以便发生错误时进行回滚。但是存储引擎为MyISAM的数据表是不支持事务的,如果不清楚可以看这个:InnoDB和MyISAM的区别,或者自行百度。

并不是所有的表都用InnoDB最好,还是得看具体的应用场景,但是这里使用InnoDB肯定没问题。那最后解决办法也很简单,就是把表的引擎改成innodb,命令如下:alter table tablename engine=innodb

你可能感兴趣的:(数据库,sql,数据库,mysql)