开发者学堂课程【MySQL 高级应用 - 索引和锁:行锁演示答疑补充】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/598/detail/8635
行锁演示答疑补充
一、行锁演示的补充讲解
1.首先取消 innobd 的 commit 自动提交
两表中均为 set autocommit=0,即两方都已取消了自动提交。
session-
mysq1>select* feom test_innodb_lock;
+------+--------+
| a | b |
+------+--------+
| 1 | b2 |
| 3 | 3 |
| 4 | 4008 |
| 5 | 5000 |
| 6 | 6000 |
| 7 | 7000 |
| 8 | 8000 |
| 9 | 9001 |
| 1 | b1 |
+------+--------+
9 rows in set (0.00 sec )
mysq1>select* feom test_innodb_lock set b='41.33' where a = 4;
Query OK, 1 row affected (0.00 sec )
Rowsmatched:1 Changed:1 Warnings :0
//session-1一旦进行 Query OK 语句后,由于取消了自动提交,则将更改后的数据41.33进行了显示。
session-2
mysq1>select* feom test_innodb_lock;
+------+--------+
| a | b |
+------+--------+
| 1 | b2 |
| 3 | 3 |
| 4 | 4008 |
| 5 | 5000 |
| 6 | 6000 |
| 7 | 7000 |
| 8 | 8000 |
| 9 | 9001 |
| 1 | b1 |
+------+--------+
9 rows in set (0.00 sec )
mysq1>select* feom test_innodb_lock
;
+------+--------+
| a | b |
+------+--------+
| 1 | b2 |
| 3 | 3 |
| 4 | 4008 |
| 5 | 5000 |
| 6 | 6000 |
| 7 | 7000 |
| 8 | 8000 |
| 9 | 9001 |
| 1 | b1 |
+------+--------+
9 rows in set (0.00 sec )
mysq1>from test_innodb_1ock ;
+------+--------+
| a | b |
+------+--------+
| 1 | b2 |
| 3 | 3 |
| 4 |41.33 |
| 5 | 5000 |
| 6 | 6000 |
| 7 | 7000 |
| 8 | 8000 |
| 9 | 9001 |
| 1 | b1 |
+------+--------+
9 rows in set (0.00 sec )mysq1>
//即进行了更多一次的 innodb_1ock才得到了相同的4号记录
此时 session-2尚未 commit,4号记录将仍然显示为4008
2.当前两窗口状态都为“set autocommit=0”,再增加第三个窗口【session-3】
[root@atguigu ~]#mysq1 -u root -p
Enter password;
We1come to the MySQL monitor.Commands end with : org.
Your MySQL connection id is 6
Server version: 5.5.48-1og MySQL Community Server ( GPL,)
Copyright (c) 2000, 2016, Orac1e and/or its affiliates.A11rights reserved.
Orac1e is a registered trademark of Orac1e Corporation and/oritsaffiliates.Other names may be trademarks of their respectivemowners.
Type "he1p;' or '\h' for he1p. Type "lc' to c1ear the current input statement .
mysq1> use db0629
Database changed
mysq1>select * from test_innodb_1ock ;
+------+--------+
| a | b |
+------+--------+
| 1 | b2 |
| 3 | 3 |
| 4 |41.33 |
| 5 | 5000 |
| 6 | 6000 |
| 7 | 7000 |
| 8 | 8000 |
| 9 | 9001 |
| 1 | b1 |
+------+--------+
9 rows in set (0.00 sec )
mysq1>
session-2的“commit”这一操作仅是为了补充“自我提交”这一未完成项,并无问题。