MySql transaction isolation level and lock description

Source: Internet
Author: User
MySql transaction isolation level and lock briefly describes the transaction feature ACID, namely atomicity, consistency, isolation, and durability. Atomicity ensures that a transaction is a minimum unit, and internal non-segmentation consistency ensures that each operation thread in the transaction cannot be submitted separately. If successful, the transaction is committed together, if the transaction fails, the transaction rollback isolation ensures that the data view between different transactions is consistent.

MySql transaction isolation level and lock briefly describes the transaction feature ACID, namely atomicity, consistency, isolation, and durability. Atomicity ensures that a transaction is a minimum unit, and internal non-segmentation consistency ensures that each operation thread in the transaction cannot be submitted separately. If successful, the transaction is committed together, if the transaction fails, the transaction rollback isolation ensures that the data view between different transactions is consistent.

MySql transaction isolation level and lock description

The characteristic ACID of a transaction, that is, atomicity, consistency, isolation, and durability.

Atomicity ensures that a transaction is a minimum unit, which is inseparable from each other.

Consistency ensures that each operation thread in the transaction cannot be submitted separately. If the operation is successful, the transaction is committed together. If the operation fails, the transaction is rolled back.

Isolation ensures that the data views seen by different transactions are isolated from each other (isolation level can be set)

Durability ensures that the data is permanently saved after the transaction is committed.

?

There are four database isolation levels-- High-performance mysql

Another case is Lost Update. Transaction A and transaction B Update data d1. After commit, transaction A rolls back the data and A sees that the modification does not take effect, lost. Read uncommitted can avoid this situation.

?

MySql lock description

The types can be divided into shared lock and exclusive lock, read lock, and write lock ).

Table sharding locks and row locks are divided according to the granularity. Table locks are implemented by the database server, and row locks are implemented by the storage engine.

?

Shared lock

The granularity of the shared locks is rows or tuples (multiple rows ). After a transaction acquires a shared lock, it can perform read operations on the data within the lock range .?

Exclusive lock

The granularity of the exclusive lock is the same as that of the shared lock. After a transaction obtains the exclusive lock, it can perform write operations on the data within the lock range.

?

Assume that there are two transactions t1 and t2

If transaction t1 acquires the shared lock of A tuples, transaction t2 can also immediately obtain the shared lock of the tuples, but cannot immediately obtain the exclusive lock of the tuples (after t1 releases the shared lock ).

If transaction t1 acquires the exclusive lock of A tuples, transaction t2 cannot immediately obtain the exclusive lock of the tuples or immediately obtain the exclusive lock of the tuples (after t1 releases the exclusive lock ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.