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
Preface A character set is a set of symbols and e...
Recently, the business side reported that some us...
Absolute, relative and fixed in position position...
Get daily statistics When doing a project, you ne...
Table of contents Initialize MySQL Install MySQL ...
Overview Prometheus is an open source service mon...
Windows installation mysql-5.7.17-winx64.zip meth...
Now, let me ask you a question. What happens when...
Jenkins configuration of user role permissions re...
Table of contents What is native JavaScript A. Ch...
1. Download from the official website and unzip h...
Preface ORDER BY 字段名升序/降序, I believe that everyon...
Deployment environment: docker container, liunx s...
Background of the problem The server monitoring s...
This article describes the commonly used MySQL fu...