Get the App
SLTechnology News&Howtos  ›  Database  › 

MySQL Database Promotion-transactions

Shulou Source: shulou.com Published: 2022-06-01 07:54:00 10月02日 Update

Day08 MySQL Database Promotion-transactions

I. Overview of transactions:

Transactions, which are made up of one or more sql statements in a single unit, are also an important part of the MySQL database. Each unit is interdependent and cannot be separated as a whole. If an error or failure occurs in a unit, the whole unit will be rolled back and all affected data will be returned to the state before the start of the transaction.

2. Transaction:

1. Nature of the transaction:

Atomicity: a transaction is a whole and cannot be divided.

Consistency: in the process of dealing with a transaction, both the success of the transaction and the failure of some links will lead to success or failure.

Isolation: each transaction takes place in its own space and does not affect other transactions.

Persistence: a committed transaction persists even if the database crashes.

2. Steps to create a transaction:

2.1. Initialize the transaction:

Start transaction

2.2. Create a transaction

Here we use an insert command to create a transaction insert into student (id,name,password) values (001 recording xxxx recording recording yyyyy')

2.3. Check that the data is entered normally.

Select * from student where id=001

2.4. Commit transaction

Commit

3. Undo transaction (transaction rollback)

Rollback

4. Set MySQL control behavior

4.1. Turn off autocommit

Set autocommit = 0

4.2. View the status of automatic submission

Select @ @ autocommit

III. Concluding remarks

At this point, the transaction of the MySQL database is finished, which is the most basic thing. Learn these things well and be able to use them in the follow-up development process. So that you can go further.

Tags: Transaction data database unit success thing whole state process influence importance consistency consistency inter atom command foundation multiple finished property Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple Redmi MySQL Huawei