事务_事务隔离级别演示1
演示:
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
#开启事务
START TRANSACTION;
#1.莫凡账户 - 500元
UPDATE accont SET balance = balance -500 WHERE NAME ='mofan';
#2.王耀账户 + 500元
UPDATE accont SET balance = balance +500 WHERE NAME ='wangyao';
#设置隔离级别 SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; #查询隔离级别 SELECT @@transaction_isolation; #开启事务 START TRANSACTION; #1.莫凡账户 - 500元 UPDATE accont SET balance = balance -500 WHERE NAME ='mofan'; #2.王耀账户 + 500元 UPDATE accont SET balance = balance +500 WHERE NAME ='wangyao'; #事务回滚 ROLLBACK; #设置隔离级别 SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED; #数据还原成1000 UPDATE accont SET balance = 1000; #开启事务 START TRANSACTION; #1.莫凡账户 - 500元 UPDATE accont SET balance = balance -500 WHERE NAME ='mofan'; #2.王耀账户 + 500元 UPDATE accont SET balance = balance +500 WHERE NAME ='wangyao'; #提交事务 COMMIT;
事务_事务隔离级别演示2
#设置隔离级别 SET GLOBAL TRANSACTION ISOLATION LEVEL REPEATABLE READ; #数据还原成1000 UPDATE accont SET balance = 1000; #开启事务 START TRANSACTION; #1.莫凡账户 - 500元 UPDATE accont SET balance = balance -500 WHERE NAME ='mofan'; #2.王耀账户 + 500元 UPDATE accont SET balance = balance +500 WHERE NAME ='wangyao'; #提交事务 COMMIT; #修改隔离级别 SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE; #开启事务 START TRANSACTION; #1.莫凡账户 - 500元 UPDATE accont SET balance = balance -500 WHERE NAME ='mofan'; #2.王耀账户 + 500元 UPDATE accont SET balance = balance +500 WHERE NAME ='wangyao';