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有相关的文档说明么?
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有相关的文档说明么?
autocommit=1的情况下
每个命令都相当启动一个新事务, 不管是什么隔离级别, 他肯定都能看到其他事务在此之前已经COMMIT的数据