select * from dept1; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 50 OPERATIONS BOSTON 20 DBA Bei Jing scott@PROD>update dept1 set deptno=21 where dname='DBA'" />
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會話事務結束,再次查詢記錄才會變化
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com