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

Summary of Common Commands for Getting Started with MySQL Database Basics

This article uses examples to describe the common...

Example of how to implement value transfer between WeChat mini program pages

Passing values ​​between mini program pages Good ...

How to handle spaces in CSS

1. Space rules Whitespace within HTML code is usu...

HTML/CSS Basics - Several precautions in HTML code writing (must read)

The warning points in this article have nothing t...

Historical Linux image processing and repair solutions

The ECS cloud server created by the historical Li...

The process of installing Docker in Linux system

In this blog, I will walk you through the process...

In-depth analysis of the Identifier Case Sensitivity problem in MySQL

In MySQL, you may encounter the problem of case s...

Summary of some tips on MySQL index knowledge

Table of contents 1. Basic knowledge of indexing ...

JavaScript adds event listeners to event delegation in batches. Detailed process

1. What is event delegation? Event delegation: Ut...

A brief discussion on macrotasks and microtasks in js

Table of contents 1. About JavaScript 2. JavaScri...

Implementation of installing Docker in win10 environment

1. Enter the Docker official website First, go to...

How to install Linux online software gcc online

Linux online installation related commands: yum i...