MySQL's business

Source: Internet
Author: User

Database Transactions (Database Transaction) refers to a series of operations performed as a single logical unit of work, either completely or completely out of execution.


Open transaction: Start transaction;
ROLLBACK TRANSACTION (if the transaction cannot be rolled back after commit): rollback;
Commit TRANSACTION: Commit;

4 major features of the transaction:
1. atomicity (automic): Multiple sets of operations in the same transaction cannot be split, must be a whole

2. Consistency (consistent): Consistent with the total amount of transaction operations before transaction operations

3. Isolation (isolation): non-interference between multiple transactions

There are 4 isolation levels of transactions in MySQL: READ UNCOMMITTED (Reading uncommitted transactions), Read committed (Read Committed transactions), REPEATABLE read (Repeatable read), serializable (serializable), (The level increases in order, and the higher the level, the greater the performance impact on the database)

View the transaction isolation level in the MySQL software: select @ @tx_isolation;

Modify the default isolation level for MySQL software: Set global transaction ISOLATION level isolation levels

SET GLOBAL TRANSACTION Isolation level READ COMMITTED;

 

 Different isolation levels can cause different problems:

When MySQL's transaction isolation level is read UNCOMMITTED, it causes dirty reads : One transaction can read uncommitted data from another transaction.

WORKAROUND: Change the transaction isolation level to read Committed,set GLOBAL TRANSACTION isolation Levels Read Committed;

When the transaction isolation level of the MySQL software is read committed, non- repeatable reads are thrown: the results of multiple reads in the same thing are inconsistent.

WORKAROUND: Change the transaction isolation level to repeatable read,SET GLOBAL TRANSACTION isolation levels repeatable read;

Instead of repeatable read, if two transactions are performed concurrently, one transaction changes the data, and the data result of the other transaction query does not affect, does not change, and remains the data before the change.

When the transaction isolation level of the MySQL software is repeatable read, it causes a virtual read (Phantom Read):

4. Persistence (Durable): Once the data is entered into the library, the table is permanently present

MySQL transaction

Related Article

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.