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

CentOS7 configuration Alibaba Cloud yum source method code

Open the centos yum folder Enter the command cd /...

How to use ss command instead of netstat in Linux operation and maintenance

Preface When operating and managing Linux servers...

Solve the problem of running hello-world after docker installation

Installed Docker V1.13.1 on centos7.3 using yum B...

Detailed explanation of how to implement secondary cache with MySQL and Redis

Redis Introduction Redis is completely open sourc...

Common commands for deploying influxdb and mongo using docker

Deploy database based on docker sudo docker pull ...

Web page production TD can also overflow hidden display

Perhaps when I name this article like this, someon...

30 free high-quality English ribbon fonts

30 free high-quality English ribbon fonts for down...

A brief introduction to React

Table of contents 1. CDN introduction 1.1 react (...

CSS3 overflow property explained

1. Overflow Overflow is overflow (container). Whe...

Analysis of the principles and usage of Linux hard links and soft links

In the Linux system, there is a kind of file call...

Vue parent-child component mutual value transfer and call

Table of contents 1. Parent passes value to child...

MySQL sql_mode analysis and setting explanation

When inserting a set of data into the MySQL datab...

JavaScript Basics Operators

Table of contents 1. Operators Summarize 1. Opera...

How to install binary MySQL on Linux and crack MySQL password

1. Make sure the system has the required libaio s...