再将binlog日志名目改为STATAMENT名目(全局及会话级都改一下,可能修改全局变量后从头登录也行,虽然 只改会话级此外也可以测试),然后 再次举办测试。
步调说明如下:
步调1 - 别离查察两个会话中的事务断绝级别及binlog名目(断绝级别均为RR,binlog为STATENENT名目)
步调2 - SESSION A 开启事务,更新users 表中c_id字段存在于class表中的记录,功效为5笔记录均更新,并将c_note内容更新为 t1
步调3- SESSION B 开启事务,筹备删除class表中 c_id便是2的记录,此时无法更新,处于阻塞状态,当即举办步调4
步调4- SESSION A 在SESSION B执行commit的行动,则SESSION B的删除操纵可以执行通过,但留意class表的数据两个SESSION中查察到的是纷歧样的
步调5- 此时SESSION B执行commit,不然后头session A 更新数据时也会阻塞。此时假如SESSION A不执行commit,查察class表的功效也是纷歧样的,如步调中的环境
步调6- SESSION A 开启事务,更新users 表中c_id字段存在于class表中的记录,功效为3笔记录更新乐成,并将c_note内容更新为 t2,别的2笔记录固然本此时查察class表中存在对应的c_id,可是不会更新,此时提交事务,然后再次查察class的内容,功效和SESSION B 查察的功效一致了(幻读)
步调7- 在从库查察users、class表中的内容,数据与主库一致
步 骤 SESSION A SESSION B1
mysql>show variables like '%iso%';
+-----------------------+-----------------+
| Variable_name | Value |
+-----------------------+-----------------+
| transaction_isolation | REPEATABLE-READ |
| tx_isolation | REPEATABLE-READ |
+-----------------------+-----------------+
2 rows in set (0.01 sec)
mysql>show variables like '%binlog_format%';
+---------------+-----------+
| Variable_name | Value |
+---------------+-----------+
| binlog_format | STATEMENT |
+---------------+-----------+
1 row in set (0.01 sec)
mysql>show variables like '%iso%';
+-----------------------+-----------------+
| Variable_name | Value |
+-----------------------+-----------------+
| transaction_isolation | REPEATABLE-READ |
| tx_isolation | REPEATABLE-READ |
+-----------------------+-----------------+
2 rows in set (0.01 sec)
mysql>show variables like '%binlog_format%';
+---------------+-----------+
| Variable_name | Value |
+---------------+-----------+
| binlog_format | STATEMENT |
+---------------+-----------+
1 row in set (0.01 sec)
2
root@testdb:3306 12:37:04>set autocommit=0;
Query OK, 0 rows affected (0.00 sec)
root@testdb:3306 12:37:17>update users set c_note='t1' where c_id in (select c_id from class);
Query OK, 5 rows affected, 1 warning (0.00 sec)
Rows matched: 5 Changed: 5 Warnings: 1
3
root@testdb:3306 12:28:25>set autocommit=0;
Query OK, 0 rows affected (0.00 sec)
root@testdb:3306 12:38:06>delete from class where c_id=2;
Query OK, 1 row affected (4.74 sec)
4
root@testdb:3306 12:38:09>commit;
Query OK, 0 rows affected (0.00 sec)
root@testdb:3306 12:38:13>select * from users;
+----+-----------+------+--------+
| id | user_name | c_id | c_note |
+----+-----------+------+--------+
| 1 | 刘备 | 2 | t1 |
| 2 | 曹操 | 1 | t1 |
| 3 | 孙 权 | 3 | t1 |
| 4 | 关羽 | 2 | t1 |
| 5 | 司马懿 | 1 | t1 |
+----+-----------+------+--------+
5 rows in set (0.00 sec)
root@testdb:3306 12:39:07>select * from class;
+------+--------+--------+
| c_id | c_name | c_note |
+------+--------+--------+
| 1 | 魏 | NULL |
| 2 | 蜀 | NULL |
| 3 | 吴 | NULL |
| 4 | 晋 | |
+------+--------+--------+
4 rows in set (0.00 sec)
5
root@testdb:3306 12:38:13>commit;
Query OK, 0 rows affected (0.00 sec)
root@testdb:3306 12:39:56>select * from class ;
+------+--------+--------+
| c_id | c_name | c_note |
+------+--------+--------+
| 1 | 魏 | NULL |
| 3 | 吴 | NULL |
| 4 | 晋 | |
+------+--------+--------+
3 rows in set (0.00 sec)
6
root@testdb:3306 12:52:23>update users set c_note='t2' where c_id in (select c_id from class);
Query OK, 3 rows affected, 1 warning (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 1
root@testdb:3306 12:52:45>select * from class;
+------+--------+--------+
| c_id | c_name | c_note |
+------+--------+--------+
| 1 | 魏 | NULL |
| 2 | 蜀 | NULL |
| 3 | 吴 | NULL |
| 4 | 晋 | |
+------+--------+--------+
4 rows in set (0.00 sec)
root@testdb:3306 12:52:49>select * from users;
+----+-----------+------+--------+
| id | user_name | c_id | c_note |
+----+-----------+------+--------+
| 1 | 刘备 | 2 | t1 |
| 2 | 曹操 | 1 | t2 |
| 3 | 孙 权 | 3 | t2 |
| 4 | 关羽 | 2 | t1 |
| 5 | 司马懿 | 1 | t2 |
+----+-----------+------+--------+
5 rows in set (0.01 sec)
root@testdb:3306 12:53:03>commit;
Query OK, 0 rows affected (0.00 sec)
root@testdb:3306 12:53:06>select * from users;
+----+-----------+------+--------+
| id | user_name | c_id | c_note |
+----+-----------+------+--------+
| 1 | 刘备 | 2 | t1 |
| 2 | 曹操 | 1 | t2 |
| 3 | 孙 权 | 3 | t2 |
| 4 | 关羽 | 2 | t1 |
| 5 | 司马懿 | 1 | t2 |
+----+-----------+------+--------+
5 rows in set (0.00 sec)
root@testdb:3306 12:53:11>select * from class;
+------+--------+--------+
| c_id | c_name | c_note |
+------+--------+--------+
| 1 | 魏 | NULL |
| 3 | 吴 | NULL |
| 4 | 晋 | |
+------+--------+--------+
3 rows in set (0.00 sec)
7
查察从库数据
root@testdb:3307 12:44:22>select * from class;
+------+--------+--------+
| c_id | c_name | c_note |
+------+--------+--------+
| 1 | 魏 | NULL |
| 3 | 吴 | NULL |
| 4 | 晋 | |
+------+--------+--------+
3 rows in set (0.01 sec)
root@testdb:3307 12:57:07>select * from users;
+----+-----------+------+--------+
| id | user_name | c_id | c_note |
+----+-----------+------+--------+
| 1 | 刘备 | 2 | t1 |
| 2 | 曹操 | 1 | t2 |
| 3 | 孙 权 | 3 | t2 |
| 4 | 关羽 | 2 | t1 |
| 5 | 司马懿 | 1 | t2 |
+----+-----------+------+--------+
5 rows in set (0.00 sec)