mysql隔离级别与锁,接口并发响应速度的关系(1)

 默认隔离级别:可重复读

 1 原始数据 
 2 | id | name      | addr |
 3 |  6 | nick      | NULL |
 4 
 5 事务1                                      事务2
 6                                            
 7 start transaction                          start transaction
 8                                            
 9                                            select * from t_user where id=6;
10                                            // name = nick
11                                            
12 update t_user set name='lock' where id=6   
13                                            
14                                            select * from t_user where id=6;
15                                            // name = nick
16 commit;                                       
17                                            
18                                            select * from t_user where id=6;
19                                            // name = nick    
20                                            // 即使第1个事务已经提交数据,此事务中查询的结果仍然是旧值
21                                            commit;
22                                            
23                                            select * from t_user where id=6;
24                                            // name = lock


脏读                 read uncommit 第一个事务还没提交, 第二个事务就读出来了, 如果第一个事务回滚了,第二个事务读的就是错误数据
读已提交 不可重复读    read commit, 第一个事务提交之后,第二个事务可以立即查询出来,造成事务二两次读取结果可能不一样
幻读 可重复读         repeat read, 第一个事务提交之后,第二个事务读取的仍是事务开始时的值---保持不变
序列化                    第一个事务做更新时,第二个事务读取不了

2 3 的区别 https://blog.csdn.net/v123411739/article/details/39298127

  

posted @ 2018-10-25 21:42  funny_coding  阅读(253)  评论(0编辑  收藏  举报
build beautiful things, share happiness