Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the MySQL isolation levels

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail what the MySQL isolation levels are, and the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Characteristics of the business

Business has four characteristics (ACID), which are atomicity, commonality, barrier and durability.

Atomicity (Atomity): business is the smallest unit of performance and segmentation is not allowed. The atomicity of the business ensures that the action is either over or doesn't work at all.

Commonality (Consistency): data remains common before and after the performance of the business.

Isolation: when visiting the database concurrently, a user's business can not be disturbed by other services, and each concurrent business is independent of the database.

Durable: after a service is submitted. It is durable to change the data in the database, and even if something goes wrong with the database, it should not have any effect on it.

Problems caused by concurrent business

In a typical application, if multiple businesses are running concurrently, it often presents multiple business operations with the same data to complete their respective tasks (multiple users operate on common data).

Although concurrency is necessary, it may lead to the following problems.

1. Dirty reading (DirtyRead)

When a business is visiting the data and correcting the data, and the correction has not been submitted to the database, another business visits the data and then uses the data. Because this data is data that has not been submitted yet, and this data may not be submitted to the database in the end, then the data read by another business is dirty data, and the operation based on dirty data may be incorrect.

two。 Drop correction (LosttoModify)

When one business reads a data, another business also visits the data, so after the data is corrected in the first business, the second business also modifies the data. This may lead to the loss of the amendment in the first business, because in fact, the amendment that takes effect after all is the amendment made by the second business, which is to lose the amendment. For example, business 1 reads the data in a table called A=A-1 21, and business 2 also reads data from business 21. When business 1 corrects A=A-1, business 2 also modifies A=A-1, but the final result is Aban 20, and the correction of business 1 is discarded.

3. No repeat (Unrepeatableread)

No repeated reading refers to the situation in which the same data is read repeatedly in a business, but the data read before and after the two times are not the same. Because before the completion of this business, another business may also visit the data, which may lead to the problem that the data read by the first business is different between the two readings in the first business due to the correction of the second business. A situation in which two different data are read in the same business is called not to be read repeatedly.

4. Fantasy reading (PhantomRead)

Phantom reading is similar to repetition. It occurs when one service (T1) reads several rows of data, and then another concurrent service (T2) inserts some data. In the subsequent query, the first business (T1) will find more records that do not exist, as if there were hallucinations, so it is called phantom reading.

No, the difference between repetition and hallucination.

The main point of no repetition is revision, emphasizing the state of the record, such as some attributes in the record, while the main point of illusion is to add or delete, emphasizing the number of records, such as more or less records.

Do not repeat such as (the same condition, you have read the data, read it again and found that the value is different): Mr. An in Business 1 has not finished reading his balance of 1000. Mr. B in Business 2 revised Mr. A's balance to 2000, causing Mr. A to change the balance to 2000 when he read his balance again, which means you can't repeat it.

Illusions such as (the same conditions, the number of records read out for the first time and the second time are not the same): if there are 24 people in the salary sheet table whose salary is greater than 1W, business 1 reads all the people whose salary is greater than 1W, and a total of 24 records are found. At this time, Business 2 inserted a record with a salary greater than 1W, and the record found when Business 1 read again became 25, which led to illusory reading.

What about the MySQL isolation level to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report