Mysql transaction personal understanding research CRMEB multi-merchant see transaction, for transaction personal understanding record; Click on the source code to download: github.crmeb.net/u/lin a. What is a transaction.

Before mysql 5.5, the default mysql engine was MyISAM. After mysql 5.5, InnoDB was introduced. One of the differences between InnoDB and mysql is that It supports transactions. A transaction is a basic unit of processing that executes once, either completely or not at all. The properties of transactions (ACID).

A, Atomicity. It can be understood as the basic unit of matter, the basic unit of our data processing operations, must be a whole indivisible. C) Consistency. Consistency refers to the database will change from the original consistent state to another consistent state after the transaction operation. This means that the database integrity constraint cannot be broken when a transaction is committed or when a transaction is rolled back. I is Isolation. It means that each transaction is independent of each other and is not affected by the execution of other transactions. This means that a transaction is not visible to other transactions until it is committed. D, for Durability. Changes made to the data after a transaction commits are persistent, even in the event of a system failure, such as a system crash or a storage medium failure. Because the database log is updated when the transaction is complete, you can use the log to restore the system to the state of the last successful update. This is where rollback logs and redo logs are concerned. Transaction usage operations.

Start transaction or begin # Start something

Savepoint # Creates a savepoint in the transaction that can be rolled back to a point later

Commint # transaction commit, where the commit is done and the changes to the database are permanent.

Rollback # restore all operations in this transaction to the state before the transaction began

Rollback to [savePoint] # Rollback to a savepoint

Release SavePoint # Delete a savepoint

Set Transaction # Set transaction isolation level

There are two ways of copying code transaction: implicit transaction and explicit transaction. The default of database is implicit transaction.

1.1. Implicit transactions. After each database change, the database is directly modified and the results are saved without the need for manual commit command, such as general add, delete, change operations;

1.2. To display the transaction, you need to commit the transaction manually after the last step.

Mysql > create table user(-> name varchar(255), -> primary key (name) ->) engine=InnoDB; Query OK, 0 rows affected (0.08 SEC)

Mysql > begin; Query OK, 0 rows affected (0.00 SEC)

Mysql > insert into user select ‘mysql ‘; Query OK, 1 row affected (0.01 SEC) Records: 1 Duplicates: 0 Warnings: 0

Mysql > select * from user; mysql> select * from user; + — — — — — — — — + | name | + — — — — — — — — + | zhang SAN | + — — — — — — — — + 1 row in the set (0.00 SEC), copy the code Here we by mysql visualization tool to view, or in the open a terminal to check

Mysql > select * from user; mysql> select * from user; Empty set

Mysql > select * from ‘mysql’ where ‘commit’;

Mysql > insert into user select ‘mysql ‘; Query OK, 1 row affected (0.01 SEC) Records: 1 Duplicates: 0 Warnings: 0 mysql> select * from user; + — — — — — — — — + | name | + — — — — — — — — + | zhang SAN | + — — — — — — — — + 1 row in the set (0.00 SEC) # mysql > commit; Query OK, 0 rows affected (0.04 SEC)

Mysql > copy code in another terminal query

mysql> select * from user; Empty set

mysql> select * from user; + — — — — — — — — + | name | + — — — — — — — — + | zhang SAN | + — — — — — — — — + 1 row in the set (0.00 SEC)

SQL > rollback rollback rollback rollback rollback rollback rollback rollback rollback rollback rollback rollback rollback The data of ‘Triple’ still does not exist the end of the transaction, which is the consistency of the transaction, the state before and after is consistent.

So that’s my personal understanding of things. If there is a wrong understanding of the place, please advise, to help you please point a link point a praise.