clinet1:
select @@tx_isolation;
+-----------------+
| @@tx_isolation  |
+-----------------+
| REPEATABLE-READ |
+-----------------+
create table t1(id int primary key auto_increment,name varchar(10));
set @@autocommit=0;
insert into t1(name) vallues('a');
commit;
切换到clinet2:
select @@tx_isolation;
+-----------------+
| @@tx_isolation  |
+-----------------+
| REPEATABLE-READ |
+-----------------+
select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
|            1 |
+--------------+
select*from t1;
+----+------+
| id | name |
+----+------+
|  1 | a    |
+----+------+
这说明发生了幻读,也就是事务的隔离级别不是REPEATABLE-READ(mysql的REPEATABLE-READ应该是可以避免幻读的吧)
set @@autocommit=0;
切换到clinet1:
insert into t1(name) vallues('b');
commit;
切换到clinet2:
select*from t1;
+----+------+
| id | name |
+----+------+
|  1 | a    |
打开clinet3:
select*from t1;
+----+------+
| id | name |
+----+------+
|  1 | a    |
|  2 | b    |
也就是说明,clinet2在将autocommit有1变为0后,防止了幻读,但问题是事务的隔离级别没有改变,mysql有相关的文档说明么?

解决方案 »

  1.   

    insert以后都commit;当然能读出来结果了
      

  2.   

    不是,set @@autocommit=0后,clinet2读不出clinet插入的数据,这不就是防止了幻读么,但是autocommit=1却发生了幻读,怎么解释?
      

  3.   

    没错, 就是这样啊
    autocommit=1的情况下
    每个命令都相当启动一个新事务, 不管是什么隔离级别, 他肯定都能看到其他事务在此之前已经COMMIT的数据