Mysql默认的隔离级别是:
(mysql@localhost) [fandb]> select @@tx_isolation;
+-----------------+
| @@tx_isolation |
+-----------------+
| REPEATABLE-READ |
+-----------------+
session A:
(mysql@localhost) [fandb]> begin;
Query OK, 0 rows affected (0.00 sec)
(mysql@localhost) [fandb]> update per1 set name='fan1' where id=1
-> ;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
(mysql@localhost) [fandb]> select * from per1 limit 1;
+----+------+
| id | name |
+----+------+
| 1 | fan1 |
+----+------+
1 row in set (0.00 sec)
A会话更新一行
session B:
(mysql@localhost) [fandb]> begin;
Query OK, 0 rows affected (0.00 sec)
(mysql@localhost) [fandb]> select * from per1 limit 1;
+----+------+
| id | name |
+----+------+
| 1 | fan |
+----+------+
1 row in set (0.00 sec)
此时在B开始事务并查询,id=1的name列并没有变化
session A:
(mysql@localhost) [fandb]> commit;
Query OK, 0 rows affected (0.00 sec)
接着A会话提交
session B:
(mysql@localhost) [fandb]> select * from per1 limit 1;
+----+------+
| id | name |
+----+------+
| 1 | fan |
+----+------+
1 row in set (0.00 sec)
在去B会话查询,还是没有变化
(mysql@localhost) [fandb]> commit;
Query OK, 0 rows affected (0.00 sec)
(mysql@localhost) [fandb]> select * from per1 limit 1;
+----+------+
| id | name |
+----+------+
| 1 | fan1 |
+----+------+
1 row in set (0.00 sec)
只有当B会话事务结束,再次查询记录才会变化