在使用Spring聲明式事務的時候,發如今作」update」時,出現異常事務能夠回滾,可是在執行」insert」的時候,後臺日誌雖然顯示回滾了,可是數據卻已經保存到了數據庫中,原本覺得是哪裏配置出錯了,後來卻發現是Mysql存儲引擎的的問題。咱們用的Mysql版本是」5.1.73」,默認存儲引擎是」MyISAM」。mysql
mysql> select version();+-----------+| version() |+-----------+| 5.1.73 |+-----------+1 row in set (0.00 sec)sql
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」就能夠了。數據庫
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」。。。微信