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;
相关文章
相关标签/搜索