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默認(rèn)的隔離級(jí)別是:
(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會(huì)話(huà)更新一行
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)
此時(shí)在B開(kāi)始事務(wù)并查詢(xún),id=1的name列并沒(méi)有變化
session A:
(mysql@localhost) [fandb]> commit;
Query OK, 0 rows affected (0.00 sec)
接著A會(huì)話(huà)提交
session B:
(mysql@localhost) [fandb]> select * from per1 limit 1;
+----+------+
| id | name |
+----+------+
| 1 | fan |
+----+------+
1 row in set (0.00 sec)
在去B會(huì)話(huà)查詢(xún),還是沒(méi)有變化
(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)
只有當(dāng)B會(huì)話(huà)事務(wù)結(jié)束,再次查詢(xún)記錄才會(huì)變化
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com