mysql事物,为什么rollback不起作用

2025-03-02 02:41:19
推荐回答(4个)
回答1:

create table staff
(
id int primary key auto_increment,
name varchar(20)
)
type = innodb;
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)

mysql> delete from staff;
Query OK, 1 row affected (0.00 sec)

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

mysql> select * from staff;
+----+-----------+
| id | name |
+----+-----------+
| 2 | zhang san |
+----+-----------+
1 row in set (0.00 sec)

我的测试结果 是回滚了

你把begin 换成 start transaction 试试

回答2:

delete from
默认提交了,你可以设置mysql的DDL语句不自动提交

回答3:

在begin;语句后加start transaction;
就可以了。

回答4:

下载一个Mysql试图开发工具 例如sqlyog