How to start a transaction in MySQL

How to start a transaction in MySQL

Preface

This article mainly introduces how to start a transaction in MySQL. You can also refer to the official documentation for related information.

https://dev.mysql.com/doc/refman/8.0/en/commit.html

Method 1

START TRANSACTION or BEGIN starts a new transaction COMMIT commits the current transaction ROLLBACK rolls back the current transaction

This is a well-known method, in which the methods of starting a transaction, start transaction and begin, are the same.

Method 2

SET autocommit = 0;

By default, autocommit = 1, which means that transactions are automatically committed.
Autommit is at the session level, which means that if autocommit is changed for the current connection, it will have no effect on other connections.
After setting autocommit, all SQL statements in this connection are in the form of transactions, such as each commit.

From the screenshot, we can see that there is a transaction in progress. Because set autocommit = 0; is set, the subsequent update operation will not modify the result, and other sessions will not be able to check it (RR level).

At this time, you need to manually execute commit.

Note that autocommit has not been changed. At this time, the autocommit value is still 0, which means that subsequent SQL statements of this session need to be committed manually.

This is the end of this article about how to start a transaction in MySQL. For more information about starting a transaction in MySQL, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Example of viewing and modifying MySQL transaction isolation level
  • How to find out uncommitted transaction information in MySQL
  • Detailed explanation of the implementation principle of ACID transaction in Mysql
  • Explanation of mysql transaction select for update and data consistency processing
  • Mysql queries the transactions being executed and how to wait for locks
  • Example of MySQL transaction processing operation implemented in Java
  • Solution to PHP+MySQL high-concurrency locked transaction processing problem

<<:  Vue implements nested routing method example

>>:  Docker deployment MySQL8 cluster (one master and two slaves) implementation steps

Recommend

How to install vim editor in Linux (Ubuntu 18.04)

You can go to the Ubuntu official website to down...

How to install mysql5.7.24 binary version on Centos 7 and how to solve it

MySQL binary installation method Download mysql h...

In-depth explanation of Vue multi-select list component

A Multi-Select is a UI element that lists all opt...

SQL implementation of LeetCode (183. Customers who have never placed an order)

[LeetCode] 183.Customers Who Never Order Suppose ...

Vue-Element-Admin integrates its own interface to realize login jump

1. First look at the request configuration file, ...

Mini Program Development to Implement Unified Management of Access_Token

Table of contents TOKEN Timer Refresher 2. Intern...

NodeJs high memory usage troubleshooting actual combat record

Preface This is an investigation caused by the ex...

MySQL 8.0 DDL atomicity feature and implementation principle

1. Overview of DDL Atomicity Before 8.0, there wa...

MySQL installation diagram summary

MySQL 5.5 installation and configuration method g...

Summary of MySQL injection bypass filtering techniques

First, let’s look at the GIF operation: Case 1: S...

A brief discussion on CSS3 animation jamming solutions

Why is it stuck? There is a premise that must be ...

Analyzing the four transaction isolation levels in MySQL through examples

Preface In database operations, in order to effec...

Detailed graphic explanation of how to clear the keep-alive cache

Table of contents Opening scene Direct rendering ...