简体   繁体   中英

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;
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. In the left half I started the transaction with 2 inserts. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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