CREATE TABLE `user` (
`USER_ID` int NOT NULL AUTO_INCREMENT,
`USER_NAME` varchar(10) DEFAULT NULL,
PRIMARY KEY (`USER_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
INSERT INTO `user` VALUES ('3', '3');
设置数据库的事务级别:提交读(一个事物内两次读取的数据不相同)
set SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
事务A;事务B
A1:start TRANSACTION;
select * from user;
B2:start TRANSACTION;
select * from user;
A3:UPDATE `test`.`user` SET `USER_ID`='3', `USER_NAME`='333' WHERE (`USER_ID`='3');
select * from user;
B4:select * from user;
我来了,我来了;
A5:A的事务提交
COMMIT;
B6:select * from user;
A事务结束,B的事务还在进行中,两次读取的参数已经变化,如果需要用username在业务中做判断;人家家中坐,BUG天上来
设置数据库的事务级别:可重复读;两次读取数据相同
set SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;