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

How to solve the dirty reading of MySQL database?

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

Share

Shulou(Shulou.com)06/01 Report--

The knowledge points of this article include: the introduction of dirty reading, the methods to solve the dirty reading of MySQL database, reading the complete article, I believe you have a certain understanding of the dirty reading of MySQL database. What is dirty reading?

Dirty reading, also known as invalid data readout, means that in database access, transaction T1 modifies a value, and then transaction T2 reads the value, and then T1 revokes the modification of the value for some reason, which results in invalid data read by T2. It is worth noting that dirty reading is generally aimed at update operations.

Solution method

The mysql database defines four isolation levels:

Serializable: can avoid dirty reading, non-repeatable reading and virtual reading.

Repeatable read: dirty and unrepeatable reading can be avoided.

Read committed: dirty reading can be avoided.

Read uncommitted: at the lowest level, it happens.

Note: the isolation level of transactions is limited by the database, and different databases support different isolation levels.

Dirty reading: add an exclusive lock when modified and not released until the transaction is committed, and add a shared lock when reading (so that during the process of reading the data in transaction 1, other transactions will not modify the data). No transaction is allowed to operate the data, but can only be read. After 1, if there is an update operation, it will be converted to an exclusive lock, and other transactions have no right to participate in reading and writing, so as to prevent dirty reading.

However, when transaction 1 reads the data, it is possible that other transactions also read the data and the shared lock is released after reading. At this time, transaction 1 modifies the data, completes the modification and commits the transaction. When other transactions read the data again, it is found that the data is inconsistent, so the problem of non-repeatable reading can not be avoided.

A variety of different problems can occur when different isolation levels are performed. The following is a summary of them and examples:

Dirty reading occurs when one transaction A reads data that has been modified by another transaction B but has not yet been committed. If B falls back, transaction A reads invalid data. This is similar to an unrepeatable read, but the second transaction does not need to perform a commit.

The above is the solution to dirty reading in MySQL database. Is there anything to gain after reading it? If you want to know more about it, you are welcome to follow the industry information!

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