MySQL Variables autocommit 数据库 参数变量解释及正确配置使用

本站中文解释

MySQL参数变量 autocommit 的功能是用来控制事务自动提交操作,默认情况下 autocommit 的值被设置为 1。这样一来,在 ANSI SQL 标准中,每次出现 DML (data manipulation language) 语句,都会被自动提交,也就是说,每次操作数据库时,都会启动一个新的事务,操作完成后以提交,不需要外部操作。

设置 autocommit 的变量值有两种主要方法:在 MySQL 命令行中或者通过使用 SET 语句。

1.在MySQL命令行中,可以使用–autocommit参数来设置autocommit的变量值,具体语法如下:
mysql> mysql –autocommit={0|1|ON|OFF} [other options]
2.通过SET语句来改变autocommit的变量值,具体语法如下:
mysql> SET GLOBAL autocommit = {0|1|ON|OFF};
mysql> SET SESSION autocommit = {0|1|ON|OFF};

官方英文解释

autocommit

Command-Line Format --autocommit[={OFF|ON}]
System Variable autocommit
Scope Global, Session
Dynamic Yes
Type Boolean
Default Value ON

The autocommit mode. If set to 1, all changes to a table take
effect immediately. If set to 0, you must use
COMMIT to accept a transaction
or ROLLBACK
to cancel it. If autocommit
is 0 and you change it to 1, MySQL performs an automatic
COMMIT of any open transaction.
Another way to begin a transaction is to use a
START
TRANSACTION
or
BEGIN
statement. See Section 13.3.1, “START TRANSACTION, COMMIT, and ROLLBACK Statements”.

By default, client connections begin with
autocommit set to 1. To cause
clients to begin with a default of 0, set the global
autocommit value by starting
the server with the
--autocommit=0 option. To set
the variable using an option file, include these lines:

[mysqld]
autocommit=0

数据运维技术 » MySQL Variables autocommit 数据库 参数变量解释及正确配置使用