学习参考https://www.bilibili.com/video/BV1Kr4y1i7ru?spm_id_from=333.999.0.0
目录

一.事物操作

elect*from account where name = '张三';
update account set money = money-1000 where name = '张三';
update account set money = money+1000 where name = '李四';


1.查看事务提交方式
select @@autocommit;

1是自动(TRUE)
set @@autocommit = 0;
在执行
select*from account where name = '张三';
update account set money = money-1000 where name = '张三';
update account set money = money+1000 where name = '李四';
表中的内容自己发生了改变

2是手动(FALSE)
2.提交事务
commit;
事物手动提交,表面修改了数据库的数据,实际并没有,此时还需要commit手动提交
3.回滚事物
rollback;


4.开启事务
start transaction;
二.事物四大特性

三.并发事物问题

四.事物隔离级别
用于解决并发事物问题


select @@transaction_isolation;

set session transaction isolation level read uncommitted;

(1) read uncommit

读取到了未提交的事务,账读
(2) read commit


成功解决账读问题。

同一个事务里查出不同的结果,出现不可重复读问题
(3)repeatable read

读取到的是未修改前的数据,即使右侧已经提交了事务。

将左侧事务提交后才能读到被修改后的数据
解决了不可重复读问题。

幻读问题,在右侧插入id = 3 的数据的情况下,左侧无法读取到这个修改,但是要插入的时候发现已经有了,出现幻读问题
(4)serializable

右侧事务要插入数据,要等待左侧事务提交后才能插入成功,否则阻塞
解决了幻读问题。
(跟操作系统解决并发问题的操作一模一样)
1750

被折叠的 条评论
为什么被折叠?



