在使用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」。。。數據庫
如感受文章對你有所幫助,能夠關注微信公衆號【五彩的顏色】鼓勵一下
微信