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;
相關文章
相關標籤/搜索