在使用Spring声明式事务的时候,发如今作”update”时,出现异常事务能够回滚,可是在执行”insert”的时候,后台日志虽然显示回滚了,可是数据却已经保存到了数据库中,原本觉得是哪里配置出错了,后来却发现是Mysql存储引擎的的问题。咱们用的Mysql版本是”5.1.73”,默认存储引擎是”MyISAM”。mysql
mysql> select version(); +-----------+ | version() | +-----------+ | 5.1.73 | +-----------+ 1 row in set (0.00 sec)
mysql> SHOW ENGINES; +------------+---------+------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +------------+---------+------------------------------------------------------------+--------------+------+------------+ | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | CSV | YES | CSV storage engine | NO | NO | NO | | MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO | | InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | +------------+---------+------------------------------------------------------------+--------------+------+------------+ 5 rows in set (0.00 sec)
到了这里缘由就了然了,建立表时默认为”MyISAM”,关于”MyISAM”和”InnoDB”及其余的各类存储引擎的区别这里就不展开了,咱们只须要将咱们的表的存储引擎改成”InnoDB”就能够了。sql
SHOW TABLE STATUS FROM database; ALTER TABLE table_name ENGINE = InnoDB; mysql> ALTER TABLE table_name ENGINE = InnoDB; Query OK, 8 rows affected (0.03 sec) Records: 8 Duplicates: 0 Warnings: 0
若是是主库的话,最好是把默认的存储引擎改成 “InnoDB”。。。数据库
如感受文章对你有所帮助,能够关注微信公众号【五彩的颜色】鼓励一下 微信