The difference MYSQL and INNODB of MYISAM

myisam supports only table-level locking, do not support the things that can mimic the transaction, but consume very large (greater than for additions and deletions to the look-up table);

innodb is row-level locking, support for things (for additions and deletions larger than table queries, the default is innodb engine);

Here Insert Picture Description
Concurrency issues brought

  • Dirty read : A transaction data read another transaction has not been submitted;
    Solution: adjust the transaction isolation level to READ COMMITTED, namely SET TRAN ISOLATION LEVEL READ COMMITTED. Then we repeat the above action will find two transactions will wait until a transaction is finished and then returns the result, since the transaction has to have his own ROLLBACK change, so the transaction can be two return correct results.

  • Magic Reading : A transaction has a read range of records, but a different number of records read twice;
    Solution: adjust the transaction isolation level to SERIALIZABLE. Use SET TRAN ISOLATION LEVEL SERIALIZABLE. Then we repeat the above action will find two transactions will wait until a transaction is finished and then returns the result.

  • Non-repeatable read : A transaction has read the same record, but different data two reads;
    Solution: adjust the transaction isolation level to REPEATABLE READ. Use SET TRAN ISOLATION LEVEL REPEATABLE READ. Then we repeat the above action will find two transactions will wait until a transaction is finished and then returns the result.

  • Lost updates : two transactions simultaneously modify a data, updating a transaction must have lost;
    Solution: adjust the transaction isolation level to READ COMMITTED, namely SET TRAN ISOLATION LEVEL READ COMMITTED;

Lost updates For chestnuts
such as 5,000 dollars, two individuals simultaneously, I saved you deposit 500 1000, then the result is 6000, then updated 500 lost, less 500, so it needs exclusive lock, at the same time, only a person exclusive data, to change other people have to wait for me to change completely;

When ready to update SQL Server data, it first update of data objects as locks, so that the data can not be modified, but you can read. When SQL Server determines the data to be updated until the operation, he will automatically update lock to an exclusive lock change, when there are other locks exist on an object, it can not lock plus updates.
Whether the update, or delete all need to go to the query
then, in order to improve data availability, so use U-lock. . Meaning, I am now in a query, but wait for the next update, so you can check, but if you want to update the like, that I have to wait to finish updating
for example, that update is actually divided into two steps,
1. will first need to update the data row found (this query process will only add S lock on these lines)
2. after finishing up, start the update (when this update, S X lock will become the lock, other threads are not allowed at this time additions and deletions to change search)
this is a whole process, called U lock
contains relations, update locks contain S and X, U lock and no real meaning, core or S and X;

Guess you like

Origin blog.csdn.net/yuanting_/article/details/96477003