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 is the transaction of MySQL

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly tells you briefly what is the transaction processing of MySQL. You can look up the relevant professional terms on the Internet or find some related books to supplement them. We will not dabble here, so let's go straight to the topic. I hope this article on what is the transaction processing of MySQL can bring you some practical help.

Transaction processing of MySQL

Steps:

1. Open transaction start transaction

When we start a transaction, our operations on sql take place in memory, but there is no real feedback to the file on the database disk!

two。 Roll back rollback

Rollback is to return to the original state before the transaction starts!

Note: the rollback operation will automatically close a transaction. If you want to execute the transaction again, you need to reopen the transaction!

3. Submit commit

The basic principles of transactions

Ordinary execution is executed immediately and takes effect, because by default, MySQL's execution of sql statements is automatically committed! Therefore, the essence of opening a transaction is to turn off the previous auto-commit function, but by the user to manually commit (using the commit statement)! [recommended for related video tutorials: MySQL tutorial]

Steps to summarize the transaction:

1. Start the transaction

2. If the execution is successful, submit the commit.

3. If any of the sql statements fail, roll back rollback!

An example of a transaction:

The most typical transaction is borrowing and repaying money. Take Zhang San's return of 1000 yuan to Li Si as an example:

First check the respective amount of money in the database

Here is the code to handle the repayment transaction:

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