MySQL事务提交与回滚

提交

为了演示效果,需要打开两个终端窗口,使用同一个数据库,操作同一张表

step1:连接

  • 终端1:查询商品分类信息
select * from goods_cates;

step2:增加数据

  • 终端2:开启事务,插入数据
begin;
insert into goods_cates(name) values('小霸王游戏机');
  • 终端2:查询数据,此时有新增的数据
select * from goods_cates;

step3:查询

  • 终端1:查询数据,发现并没有新增的数据
select * from goods_cates;

step4:提交

  • 终端2:完成提交
commit;

step5:查询

  • 终端1:查询,发现有新增的数据
select * from goods_cates;


回滚

  • 为了演示效果,需要打开两个终端窗口,使用同一个数据库,操作同一张表

step1:连接

  • 终端1
select * from goods_cates;

step2:增加数据

  • 终端2:开启事务,插入数据
begin;
insert into goods_cates(name) values('小霸王游戏机');
  • 终端2:查询数据,此时有新增的数据
select * from goods_cates;

step3:查询

  • 终端1:查询数据,发现并没有新增的数据
select * from goods_cates;

step4:回滚

  • 终端2:完成回滚
rollback;

step5:查询

  • 终端1:查询数据,发现没有新增的数据
select * from goods_cates;
原文地址:https://www.cnblogs.com/john-xiong/p/11818723.html