饿虎岗资源网 Design By www.oxmxm.com
查看mysql 事务隔离级别
mysql> show variables like '%isolation%'; +---------------+----------------+ | Variable_name | Value | +---------------+----------------+ | tx_isolation | READ-COMMITTED | +---------------+----------------+ 1 row in set (0.00 sec)
可以看到当前的事务隔离级别为 READ-COMMITTED 读提交
下面看看当前隔离级别下的事务隔离详情,开启两个查询终端A、B。
下面有一个order表,初始数据如下
mysql> select * from `order`; +----+--------+ | id | number | +----+--------+ | 13 | 1 | +----+--------+ 1 row in set (0.00 sec)
第一步,在A,B中都开启事务
mysql> start transaction; Query OK, 0 rows affected (0.00 sec)
第二步查询两个终端中的number值
A
mysql> select * from `order`; +----+--------+ | id | number | +----+--------+ | 13 | 1 | +----+--------+ 1 row in set (0.00 sec)
B
mysql> select * from `order`; +----+--------+ | id | number | +----+--------+ | 13 | 1 | +----+--------+ 1 row in set (0.00 sec)
第三步将B中的number修改为2,但不提交事务
mysql> update `order` set number=2; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
第四步查询A中的值
mysql> select * from `order`; +----+--------+ | id | number | +----+--------+ | 13 | 1 | +----+--------+ 1 row in set (0.00 sec)
发现A中的值并没有修改。
第五步,提交事务B,再次查询A中的值
B
mysql> commit; Query OK, 0 rows affected (0.01 sec)
A
mysql> select * from `order`; +----+--------+ | id | number | +----+--------+ | 13 | 2 | +----+--------+ 1 row in set (0.00 sec)
发现A中的值已经更改
第六步,提交A中的事务,再次查询A,B的值。
A
mysql> commit; Query OK, 0 rows affected (0.00 sec) mysql> select * from `order`; +----+--------+ | id | number | +----+--------+ | 13 | 2 | +----+--------+ 1 row in set (0.00 sec)
B
mysql> select * from `order`; +----+--------+ | id | number | +----+--------+ | 13 | 2 | +----+--------+ 1 row in set (0.00 sec)
发现A,B中的值都更改为2了。
下面给一个简单的示意图
我们可以看到,在事务隔离级别为读已提交 的情况下,当B中事务提交了之后,即使A未提交也可以读到B事务提交的结果。这样解决了脏读的问题。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
饿虎岗资源网 Design By www.oxmxm.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
饿虎岗资源网 Design By www.oxmxm.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 《绝对主打 流行原创金曲 2CD》[WAV分轨][1.1GB]
- 《赛博朋克2077》更新上线:支持AMD FSR3
- 《塞尔达传说:智慧的再现》提前半个月偷跑,引发玩家担忧
- 战锤40K星际战士2全职业介绍|全职业技能效果一览
- 陈百强《2006世纪10星·永恒篇[环球]》[WAV整轨]
- 【新世纪钢琴】VA-GoldenOctober(Piano)(金秋十月钢琴篇)【FLAC】
- 青稞荞麦《破茧》新生代组合[WAV+CUE]
- 因系统升级后出现BUG 《FF16》PS5完全版宣布延期
- 《黑神话:悟空》周伯通!大佬用左右手分别挑战两只虎先锋
- 《黑神话:悟空》攻击动作致敬《大话西游》:这也太帅了!
- 《星舰铳犬太阳系物语》游戏背景介绍
- 《战锤40K星际战士2》终极版有后续DLC说明
- 《第9层》游戏特色玩法介绍
- 刀郎.2006-刀郎【九雨天下】【WAV+CUE】
- 59.9高校生.1994-素兰万岁【上华】【WAV+CUE】