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 common questions about transactions in MySQL?

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

Share

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

In this issue, the editor will bring you what are the common questions about MySQL about affairs. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

The so-called transaction refers to a set of interdependent operating units, which is used to ensure the correct modification of the database and maintain the integrity of the data. if a unit operation of a transaction fails, all operations of this transaction will be cancelled. In theory, transactions should be completely isolated from each other to avoid problems caused by concurrent transactions, but this can have a significant impact on performance because transactions must be run sequentially. In practice, in order to improve performance, transactions run at a lower isolation level, and the isolation level of transactions can be specified by isolating transactions

Concurrency of transactions

Dirty read: transaction A reads the data updated by transaction B, then B rolls back the operation, and A reads dirty data.

Can not be read repeatedly: transaction A reads the same data many times, and transaction B updates and commits the data in the process of transaction A reading many times. As a result, when A reads the same data many times, the data results read twice are inconsistent.

Illusion: unrepeatable reading has been solved. Transaction A modifies a data item in all rows of a table. At this time, B has a row of data items inserted in this table, and the array of this data item is still the original value. When A looks at it, it is still the original array. In fact, this is added by B, just like an illusion.

Isolation level of the transaction

Read uncommitted: another transaction has modified the data, but has not yet committed, and the SELECT in this transaction will uniquely read the data that violates the commit.

Unrepeatable: transaction B modifies and commits data when transaction A reads a data multiple times, resulting in inconsistent results when transaction A reads multiple times

Repeatable: the result of SELECT is the state of the transaction start time, so the read result is consistent, but there may be phantom reading.

Serialization: the highest isolation level without any exception

The default transaction isolation level for MySQL is repeatableread

When the default transaction isolation level in MySQL is "repeatable read", the read row is not locked, and the write data locks the entire table.

When the transaction level in MySQL is "uncommitted read", the write data only locks the corresponding row

When the transaction level in MySQL is "serialization", both read and write data will lock the entire table

The higher the isolation level, the greater the data integrity and consistency, but the greater the impact on concurrent performance. For most applications, the isolation level of the database system can be set to Read Committed as far as possible, which can avoid dirty reads as far as possible and have better concurrency performance.

These are the common MySQL questions about affairs shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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