Does MySql need to commit?

Does MySql need to commit?

Whether MySQL needs to commit when performing operations such as insert depends on your storage engine.

If the engine does not support transactions, such as MyISAM, then commit will have no effect.

If it is an engine that supports transactions, such as InnoDB, you need to know whether your transaction supports automatic transaction submission (commit)

To see whether your database is automatically committed, you can use mysql> show variables like '%autocommit%'; to check. If it is OFF, it will not be automatically committed and you need to commit manually (you can directly use the "commit;" command on the command line). Otherwise, it will be automatically committed.

There are three types of submitted data: explicit submission, implicit submission, and automatic submission.

These three types are described below.

Explicit Commit

A commit done directly with the COMMIT command is an explicit commit.

Implicit commit

The submission completed indirectly by SQL commands is implicit submission. The commands are:

ALTER , AUDIT , COMMENT , CONNECT , CREATE , DISCONNECT , DROP , EXIT , GRANT , NOAUDIT , QUIT , REVOKE , RENAME .

Automatic submission

If AUTOCOMMIT is set to ON, after the insert, modify, or delete statement is executed,

The system will submit automatically, this is automatic submission. The format is: SQL>SET AUTOCOMMIT ON;

Be careful when using the COMMIT / ROLLBACK commands. COMMIT / ROLLBACK are used after executing DML statements (INSERT / DELETE / UPDATE / SELECT). After a DML statement is executed, the processed data will be placed in the rollback segment (except for SELECT statements), waiting for the user to commit (COMMIT) or rollback (ROLLBACK). When the user executes COMMIT / ROLLBACK, the data placed in the rollback segment will be deleted. (After the SELECT statement is executed, the data is stored in the shared pool. When providing the same data to others for query, it is directly extracted from the shared pool without going to the database, which improves the speed of data query.)

All DML statements must be explicitly committed, that is, COMMIT must be executed after the DML statement is executed. Others, such as DDL statements, are implicitly committed. That is to say, after running those non-DML statements, the database has already performed an implicit commit. For example, after running the CREATE TABLE script, the table has been created and you no longer need to perform an explicit commit.

You may also be interested in:
  • PHP+MySQL transaction rollback & commit example

<<:  DOM operation implementation in react

>>:  Virtual domain name configuration and test verification under Linux\Nginx environment

Recommend

How to use Vue cache function

Table of contents Cache function in vue2 Transfor...

vue-electron problem solution when using serialport

The error is as follows: Uncaught TypeError: Cann...

Why is UTF-8 not recommended in MySQL?

I recently encountered a bug where I was trying t...

Javascript operation mechanism Event Loop

Table of contents 1. Four concepts 1. JavaScript ...

Javascript Virtual DOM Detailed Explanation

Table of contents What is virtual dom? Why do we ...

How to successfully retrieve VMware Esxi root password after forgetting it

Prepare a CentOS6 installation disk (any version)...

How to modify the sources.list of Ubuntu 18.04 to Alibaba or Tsinghua mirror

1. Backup source list The default source of Ubunt...

How to configure SSL for koa2 service

I. Introduction 1: SSL Certificate My domain name...

MySQL intercepts the sql statement of the string function

1. left(name,4) intercepts the 4 characters on th...

Detailed explanation of Linux copy and paste in VMware virtual machine

1. Linux under VMware Workstation: 1. Update sour...

Solution to span width not being determined in Firefox or IE

Copy code The code is as follows: <html xmlns=...

Solution to the problem "Table mysql.plugin doesn't exist" when deploying MySQL

Today I deployed the free-installation version of...

What are the usages of limit in MySQL (recommended)

SELECT * FROM table name limit m,n; SELECT * FROM...

A brief talk about Mysql index and redis jump table

summary During the interview, when discussing abo...

Dealing with the problem of notes details turning gray on web pages

1. In IE, if relative positioning is used, that is...