时间:2021-07-01 10:21:17 帮助过:14人阅读
Mysql事务隔离级别之读提交
查看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)
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)
number
修改为2,但不提交事务mysql> update `order` set number=2; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from `order`; +----+--------+ | id | number | +----+--------+ | 13 | 1 | +----+--------+ 1 row in set (0.00 sec)
发现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
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事务提交的结果。这样解决了脏读
的问题。以上就是Mysql事务隔离级别内容的介绍(读提交)的详细内容,更多请关注Gxl网其它相关文章!