文章是关于事务提交的东西,以下为从mysql官网翻译来的内容,以及原英文。我只翻译了部分内容(百度翻译),基于个人理解改动了一些地方,不准确的地方,希望大家指正。
In
InnoDB
, all user activity occurs inside a transaction. Ifautocommit
mode is enabled, each SQL statement forms a single transaction on its own. By default, MySQL starts the session for each new connection withautocommit
enabled, so MySQL does a commit after each SQL statement if that statement did not return an error. If a statement returns an error, the commit or rollback behavior depends on the error. See Section 14.21.4, “InnoDB Error Handling”.
在innodb中,所有用户活动都发生在事务内部。如果启用自动提交模式,则每个SQL语句都会单独形成一个事务。默认情况下,MySQL在启用自动提交的情况下为每个新连接启动会话(每个session默认是自动提交),因此如果该语句没有返回错误,MySQL会在每个SQL语句之后进行提交。如果语句返回错误,则提交或回滚行为取决于错误。参见第14.21.4节,See Section 14.21.4, “InnoDB Error Handling”.
A session that has
autocommit
enabled can perform a multiple-statement transaction by starting it with an explicitSTART TRANSACTION
orBEGIN
statement and ending it with aCOMMIT
orROLLBACK
statement. See Section 13.3.1, “START TRANSACTION, COMMIT, and ROLLBACK Syntax”.
启用了自动提交的会话可以通过使用显式开始事务或开始语句启动多语句事务,并使用提交或回滚语句结束多语句事务(用BEGIN 或者 START TRANSACTION 开启多语句事务,COMMIT 或者 ROLLBACK 结束事务)。参见第13.3.1节, See Section 13.3.1, “START TRANSACTION, COMMIT, and ROLLBACK Syntax”.
If
autocommit
mode is disabled within a session withSET autocommit = 0
, the session always has a transaction open. ACOMMIT
orROLLBACK
statement ends the current transaction and a new one starts.
如果在设置autocommit=0的会话中禁用autocommit模式,则会话始终打开一个事务。一条commit或rollback语句结束当前事务,并启动一个新事务。
If a session that has
autocommit
disabled ends without explicitly committing the final transaction, MySQL rolls back that transaction.
如果禁用“自动提交”的会话在没有显式提交最终事务的情况下结束,MySQL将回滚该事务。
Some statements implicitly end a transaction, as if you had done a
COMMIT
before executing the statement. For details, see Section 13.3.3, “Statements That Cause an Implicit Commit”.
有些语句隐式地结束了一个事务,就好像您在执行该语句之前已经完成了提交。有关详细信息,请参见第13.3.3节“导致隐式提交的语句”。
A
COMMIT
means that the changes made in the current transaction are made permanent and become visible to other sessions. AROLLBACK
statement, on the other hand, cancels all modifications made by the current transaction. BothCOMMIT
andROLLBACK
release allInnoDB
locks that were set during the current transaction.
A提交表示当前事务中所做的更改是永久性的,并对其他会话可见。另一方面,rollback语句取消当前事务所做的所有修改。提交和回滚释放在当前事务期间设置的所有innodb锁。