Dark Horse day11 dirty Data Reading & Solutions, dark horse day11
Database:
Create table account (
Id int primary key auto_increment,
Name varchar (20 ),
Money double
);
Insert into account values (null, 'a, 100 );
Insert into account values (null, 'B', 100 );
1. Demonstrate dirty reading
Open two client windows. The level of client A is the default Repeatable read of the database-this can prevent dirty read/non-repeated read problems, but cannot prevent virtual read (phantom read) problems. Changing the level of client B to the Read uncommitted level with the highest efficiency cannot solve the dirty Read problem.
Window:
Start transaction: start transaction;
Account a transfers RMB 10 to account B: update account set money = money-10 where name = 'a ';
Add 10 RMB to account B: update account set money = money + 10 where name = 'B ';
Do not submit transactions;
Window B:
Start transaction: start transaction;
Query account B data in the database: select * from account;
Window:
Rollback transaction: rollback;
Window B:
Query data: select * from account;
Dirty read data is generated.
Solution:
Change the isolation level of window B to Read committed.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.