4-MySQL高级-事务-提交(3)

提交

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

step1:连接

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

step2:增加数据

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

step3:查询

  • 终端1:查询数据,发现并没有新增的数据(因为此时终端2并没有提交,操作的数据仍然在缓存中)
select * from goods_cates;

step4:提交

  • 终端2:完成提交
commit;

step5:查询

  • 终端1:查询,发现有新增的数据(因为此时终端2已经提交数据)
select * from goods_cates;
原文地址:https://www.cnblogs.com/summer1019/p/11053240.html