隔离级别:
REPEATABLE-READ表结构:
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;事务A:
start transaction;
select * from user;
insert into user ( name ) value('567');
select sleep(20);
select * from user;
commit;事务B:
start transaction;
select * from user;
insert into user ( name ) value('678');
select sleep(20);
select * from user;
commit;事务A的结果:
1 123
2 234
3 456
4 789
5 567
6 789
7 567事务B的结果:
1 123
2 234
3 456
4 789
5 567
6 789
8 678事务A和事务B先后执行,时间间隔不超过1秒。但是事务B,select的结果内没有查询到事务A插入的内容。事务A会走全表扫码,直到事务COMMIT,释放锁资源,事务B会等待锁。也就是事务Acommit之后。这个时候应该可以读到事务A新增的内容。但是实际上没有读到。
REPEATABLE-READ表结构:
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;事务A:
start transaction;
select * from user;
insert into user ( name ) value('567');
select sleep(20);
select * from user;
commit;事务B:
start transaction;
select * from user;
insert into user ( name ) value('678');
select sleep(20);
select * from user;
commit;事务A的结果:
1 123
2 234
3 456
4 789
5 567
6 789
7 567事务B的结果:
1 123
2 234
3 456
4 789
5 567
6 789
8 678事务A和事务B先后执行,时间间隔不超过1秒。但是事务B,select的结果内没有查询到事务A插入的内容。事务A会走全表扫码,直到事务COMMIT,释放锁资源,事务B会等待锁。也就是事务Acommit之后。这个时候应该可以读到事务A新增的内容。但是实际上没有读到。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货