MySQL 幻读

SESSION1                                                            SESSION2
mysql -uroot -h192.168.60.159 test                                  mysql -uroot -h192.168.60.159 test
delete from t;
insert into t values(1,'a');

select @@global.tx_isolation, @@tx_isolation;                       select @@global.tx_isolation, @@tx_isolation;
+-----------------------+-----------------+                         +-----------------------+-----------------+
| @@global.tx_isolation | @@tx_isolation  |                         | @@global.tx_isolation | @@tx_isolation  |
+-----------------------+-----------------+                         +-----------------------+-----------------+
| REPEATABLE-READ       | REPEATABLE-READ |                         | REPEATABLE-READ       | REPEATABLE-READ |
+-----------------------+-----------------+                         +-----------------------+-----------------+

START TRANSACTION;                                                   START TRANSACTION;
select * from t ;
Empty set (0.00 sec)
                                                                     insert into t values(2,'a');
select * from t ;
+----+------+
| id | name |
+----+------+
|  1 | a    |
+----+------+
                                                                      commit;
select * from t ;
+----+------+
| id | name |
+----+------+
|  1 | a    |
+----+------+

update t set name='z' where name='a'; 
Query OK, 2 rows affected (0.00 sec) -- 发现明明一天数据,修改的时候改了两条数据
Rows matched: 2  Changed: 2  Warnings: 0

select * from t;  --幻读出现了
+----+------+
| id | name |
+----+------+
|  1 | z    |
|  2 | z    |
+----+------+


你可能感兴趣的:(MYSQL基础)