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 does the transaction of MySQL database mean?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly introduces what the transaction of MySQL database means. It is very detailed and has certain reference value. Friends who are interested must finish it.

Database transaction refers to a series of operations performed as a single logical unit of work, either completely or not; simply put, a transaction is a concurrency control unit and a user-defined sequence of operations.

You use Alipay to go shopping in the supermarket and transfer 100 yuan to the supermarket. In fact, this is two steps:

The first step is to subtract 100 from your account in Alipay database.

The second step is to add 100 yuan to the Alipay account in the supermarket and the transaction is completed.

But what happens when there is a power outage when the first step is completed and the second step is not carried out?

It will happen, your account has been reduced by 100 yuan, the amount of the supermarket account has not changed, this will not be a problem, there is no need to fight?

In order to solve this data consistency problem, database transaction arises at the historic moment.

A transaction refers to a series of operations performed as a single logical unit of work, either completely or not at all. To put it simply, a transaction is a concurrency control unit and a user-defined sequence of operations.

It is the unit for the database to maintain data consistency. it transforms the database from a consistent state to a new consistent state. to put it simply, if a set of processing steps either occur or are not performed at all, we call the set of processing steps a transaction. In this way, the consistent state of the data is ensured, and the integrity and reliability of the data are not destroyed. After a transaction is executed, DBMS automatically checks the consistency of the data in the database.

Transactions have four characteristics, namely, Atomicity, Consistency, Isolation, and Durability, which are usually referred to as ACID.

1. Atomicity

A transaction is a complete operation. The elements of a transaction are indivisible (atomic). All elements in the transaction must be committed or rolled back as a whole. If any element in the transaction fails, the entire transaction will fail.

In the case of a bank transfer transaction, if the transaction is committed, the data for these two accounts will be updated. If, for some reason, the transaction terminates before the two accounts are successfully updated, the balance of the two accounts will not be updated, any changes to the account balance will be undone, and the transaction cannot be partially committed.

2. Consistency

When the transaction completes, the data must be in a consistent state. That is, the data stored in the database is in a consistent state before the transaction begins. In the course of an ongoing transaction. The data may be in an inconsistent state, for example, some of the data may be modified. However, when the transaction completes successfully, the data must return to its known consistent state again. Changes made to the data through the transaction cannot damage the data, or the transaction cannot make the data storage unstable.

Take bank transfer affairs as an example. The total balance of all accounts is in a consistent state before the transaction begins. In the course of the transaction, the balance of one account has been reduced, while the balance of the other has not been modified. As a result, the total amount of all account balances is inconsistent. After the transaction is completed, the total balance of the account returns to a consistent state again.

3. Isolation

All concurrent transactions that modify data are isolated from each other, indicating that transactions must be independent and should not depend on or affect other transactions in any way. A transaction that modifies data can access the data before another transaction that uses the same data starts, or after another transaction that uses the same data ends.

In addition, when a transaction modifies data, if any other process is using the same data at the same time, the modification to the data will not take effect until the transaction is successfully committed. The transfer between Zhang San and Li Si and between Wang Wu and Zhao er will always be independent of each other.

4. Persistence

The persistence of a transaction means that the result of a transaction is permanent regardless of whether the system fails or not.

After a transaction completes successfully, the changes it makes to the database are permanent, even if the system fails. That is, once the transaction is committed, any changes made by the transaction to the data are permanently retained in the database.

The ACID principle of a transaction ensures that a transaction must be either a successful commit or a failed rollback. Therefore, its modifications to the transaction are recoverable. That is, when a transaction fails, its modifications to the data will return to the state it was before the transaction was executed.

The above is all the content of this article "what does the transaction of MySQL database mean?" Thank you for reading! Hope to share the content to help you, more related knowledge, 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