简体   繁体   English

使用 InnoDB 引擎的 Mysql 事务不起作用

[英]Mysql Transaction using InnoDB engine doesn't work

the first and second insertion should be canceled (casue the second based on the first).应该取消第一次和第二次插入(假设第二次插入基于第一个)。 anyway the transaction here doesn't work it commits the first one even if the second goes error, for SET autocommit = 0 tried using = off and both inside the transaction and outside it.无论如何,这里的事务不起作用,即使第二个出错,它也会提交第一个,因为SET autocommit = 0尝试使用= off并且在事务内部和外部都使用。

SET autocommit = 0;
START TRANSACTION;
insert into rooms
values
("test","0000","0000");
insert into assign_write_rooms
values
("0000","notest","0000");
COMMIT;

i think this is not an error.我认为这不是错误。

I have startet 2 MySQL clients.我有 startet 2 MySQL 客户端。 In the left half I started the transaction with 2 inserts.在左半部分,我用 2 个插入开始了事务。 the second with a error.第二个有错误。 In the right client i cant never see the data.在正确的客户端中,我永远无法看到数据。 When i close the connection the data is rollback当我关闭连接时,数据回滚

mysql> select * from rollb;
Empty set (0.00 sec)
                                                mysql> select * from rollb;
                                                Empty set (0.00 sec)

mysql> set autocommit=0;
Query OK, 0 rows affected (0.00 sec)

mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into rollb VALUES (1);
Query OK, 1 row affected (0.00 sec)
                                                mysql> select * from rollb;
                                                Empty set (0.00 sec)


mysql> insert into rollb VALUES (1);
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> select * from rollb;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)
                                                mysql> select * from rollb;
                                                Empty set (0.00 sec)


mysql>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM