Session 1 | Session 2 | |
T1 | start transaction; | start transaction; |
T2 |
select * from user;
+----+--------+------+
| id | name | age |
+----+--------+------+
| 1 | Jammes | 23 |
| 2 | Kobe | 34 |
| 3 | Smith | 45 |
| 4 | JR | 34 |
| 5 | Yi | 45 |
+----+--------+------+
|
|
T3 |
update user set name="Polo" where name="Kobe" and age=45;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
|
|
T4 |
update user set name = "Smith" where id=5;
^C^C -- query aborted
ERROR 1317 (70100): Query execution was interrupted
|
Session 1 | Session 2 | |
T1 | start transaction; | start transaction; |
T2 |
select * from user where id = 4;
+----+-------+------+
| id | name | age |
+----+-------+------+
| 4 | Smith | 34 |
+----+-------+------+
|
|
T3 |
update user set name = 'JR' where id = 4;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
|
|
T4 |
select * from user where id = 4;
+----+------+------+
| id | name | age |
+----+------+------+
| 4 | JR | 34 |
+----+------+------+
1 row in set (0.00 sec)
|
|
T5 | Rollback; | |
T6 |
select * from user where id = 4;
+----+-------+------+
| id | name | age |
+----+-------+------+
| 4 | Smith | 34 |
+----+-------+------+
|
Session 1 | Session 2 | |
T1 | start transaction; | start transaction; |
T2 |
select * from user where id = 4;
+----+------+------+
| id | name | age |
+----+------+------+
| 4 | JR | 34 |
+----+------+------+
|
|
T3 |
update user set name = 'Smith' where id = 4;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
|
|
T4 |
select * from user where id = 4;
+----+------+------+
| id | name | age |
+----+------+------+
| 4 | JR | 34 |
+----+------+------+
1 row in set (0.00 sec)
|
|
T5 | commit; | |
T6 |
select * from user where id = 4;
+----+-------+------+
| id | name | age |
+----+-------+------+
| 4 | Smith | 34 |
+----+-------+------+
|
Session 1 | Session 2 | |
T1 | start transaction; | start transaction; |
T2 |
select * from user where id = 4;
+----+------+------+
| id | name | age |
+----+------+------+
| 4 | JR | 34 |
+----+------+------+
|
|
T3 |
update user set name = 'Smith' where id = 4;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
|
|
T4 |
select * from user where id = 4;
+----+------+------+
| id | name | age |
+----+------+------+
| 4 | JR | 34 |
+----+------+------+
1 row in set (0.00 sec)
|
|
T5 | commit; | |
T6 |
select * from user where id = 4;
+----+------+------+
| id | name | age |
+----+------+------+
| 4 | JR | 34 |
+----+------+------+
|
Session 1 | Session 2 | |
T1 | start transaction; | start transaction; |
T2 |
select * from user where id = 4;
+----+------+------+
| id | name | age |
+----+------+------+
| 4 | JR | 34 |
+----+------+------+
|
|
T3 |
update user set name = 'Smith' where id = 4;
等待锁释放……..
|
Session 1 | Session 2 | |
T1 | start transaction; | |
T2 | update user set name = "Smith" where id=4; Query OK, 1 row affected (0.00 sec) |
|
T3 | select * from user; +----+--------+———+ | id | name | age | +----+--------+———+ | 1 | Jammes | 23 | | 2 | Kobe | 34 | | 3 | Wade | 45 | | 4 | JR | 34 | +----+--------+------+ |