TransactionA transaction is a basic unit of business logic. Each transaction consists of a series of SQL statements. DML statements related to transactions ( The existence of transactions ensures the security of data. Transaction mechanism: Each execution of a DML statement will record the operation, but will not modify the data. Finally, commit the transaction (delete records, modify hard disk data) or roll back the transaction (delete records, do not modify data). Transactions have four major characteristics : ACID
Transaction isolation level: 1. This level has dirty read phenomenon 2. Read This level solves the dirty read problem, but it cannot be read repeatedly. 3. The problem of non-repeatable reads is solved, but phantom reads still exist and the data read is not real. 4. Serialized read/serialized read. All problems are solved, similar to thread safety in multithreading. But there are inefficiencies. Because transactions need to be queued. The default isolation level of the Want to commit the transaction manually. Before executing DML. First Demonstrate manual rollback of a transaction: drop table if exists t_user1; create table t_user1( id int(3) primary key auto_increment, username varchar(10) ); mysql> create table t_user1( -> id int(3) primary key auto_increment, -> username varchar(10) -> ); Query OK, 0 rows affected (0.02 sec) mysql> insert into t_user1(username) values('h1'); Query OK, 1 row affected (0.01 sec) mysql> select * from t_user1; +----+----------+ | id | username | +----+----------+ | 1 | h1 | +----+----------+ 1 row in set (0.00 sec) mysql> rollback; //Rollback transaction Query OK, 0 rows affected (0.00 sec) mysql> select * from t_user1; //After rollback, it is still the same as before, because mysql automatically submits +----+----------+ | id | username | +----+----------+ | 1 | h1 | +----+----------+ 1 row in set (0.00 sec) mysql> start transaction; //Manually start transaction, turn off automatic transaction submission Query OK, 0 rows affected (0.00 sec) mysql> insert into t_user1(username) values('h2'); Query OK, 1 row affected (0.01 sec) mysql> insert into t_user1(username) values('h3'); Query OK, 1 row affected (0.00 sec) mysql> insert into t_user1(username) values('h4'); Query OK, 1 row affected (0.00 sec) mysql> select * from t_user1; +----+----------+ | id | username | +----+----------+ | 1 | h1 | | 2 | h2 | | 3 | h3 | | 4 | h4 | +----+----------+ 4 rows in set (0.00 sec) mysql> rollback; //Rollback Query OK, 0 rows affected (0.01 sec) mysql> select * from t_user1; +----+----------+ | id | username | In the end, the data on the hard disk is still the same as before. +----+----------+ Roll back the deletion record without modifying the data on the hard disk. | 1 | h1 | +----+----------+ 1 row in set (0.00 sec) This is the end of this article about MySQL transaction analysis. For more relevant MySQL transaction content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to write object and param to play flash in firefox
>>: How to use custom images in Html to display checkboxes
Focus images are a way of presenting content that ...
Detailed explanation of MySQL exporting data from...
What is a primary key? A primary key is a column ...
Enough of small talk <br />Based on the lar...
Preface I recently sorted out my previous notes o...
Table of contents 1. Introduction to teleport 1.1...
Table of contents 1. Please explain what are the ...
When you start working on a project, it’s importa...
Table of contents 1. Decoupled assignment of arra...
Table of contents 1. Example: this can directly g...
NProgress is the progress bar that appears at the...
Table of contents 1. Monitoring port Relationship...
Data Type: The basic rules that define what data ...
1. Division of labor and process <br />At T...
Use the find command to find files larger than a ...