Mysql事务隔离级别内容的介绍(读提交)
本篇文章给大家带来的内容是关于Mysql事务隔离级别内容的介绍(读提交),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
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)第一步,在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: 1Changed: 1Warnings: 0第四步查询A中的值mysql> select * from `order`;+----+--------+| id | number |+----+--------+| 13 |1 |+----+--------+1 row in set (0.00 sec)第五步,提交事务B,再次查询A中的值Bmysql> commit;Query OK, 0 rows affected (0.01 sec)Amysql> select * from `order`;+----+--------+| id | number |+----+--------+| 13 |2 |+----+--------+1 row in set (0.00 sec)第六步,提交A中的事务,再次查询A,B的值。Amysql> commit;Query OK, 0 rows affected (0.00 sec)mysql> select * from `order`;+----+--------+| id | number |+----+--------+| 13 |2 |+----+--------+1 row in set (0.00 sec)Bmysql> select * from `order`;+----+--------+| id | number |+----+--------+| 13 |2 |+----+--------+1 row in set (0.00 sec)下面给一个简单的示意图
我们可以看到,在事务隔离级别为读已提交 的情况下,当B中事务提交了之后,即使A未提交也可以读到B事务提交的结果。这样解决了脏读的问题。以上就是Mysql事务隔离级别内容的介绍(读提交)的详细内容,更多请关注小潘博客其它相关文章!