事务在 mysql 中不起作用

Liv*_*hia 2 mysql sql transactions

我的SQL代码是:

SET AUTOCOMMIT=0;
START TRANSACTION;
BEGIN;
INSERT INTO utente(nomeutente) VALUES('pippobaudo');
INSERT INTO fonti(id_fonte, id_esame) VALUES (4, 28);
COMMIT;
Run Code Online (Sandbox Code Playgroud)

第一个INSERT 是正确的,但第二个不正确,因为我想测试交易。MySQL 理解并在第二个 INSERT 中生成错误,但令人难以置信的是,它不尊重事务并在我的数据库中插入“pippobaudo”。

请帮我!

谢谢

Álv*_*lez 5

MyISAM引擎不支持事务:

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         |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
Run Code Online (Sandbox Code Playgroud)

  • 使用支持事务的引擎:InnoDB。这是最新版本中的默认设置。 (2认同)