Mysql 事务的提交和回滚

文章是关于事务提交的东西,以下为从mysql官网翻译来的内容,以及原英文。我只翻译了部分内容(百度翻译),基于个人理解改动了一些地方,不准确的地方,希望大家指正。


In InnoDB, all user activity occurs inside a transaction. If autocommit mode is enabled, each SQL statement forms a single transaction on its own. By default, MySQL starts the session for each new connection with autocommit 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 explicit START TRANSACTION or BEGIN statement and ending it with a COMMIT or ROLLBACK 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 with SET autocommit = 0, the session always has a transaction open. A COMMIT or ROLLBACK 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. A ROLLBACK statement, on the other hand, cancels all modifications made by the current transaction. Both COMMIT and ROLLBACK release all InnoDB locks that were set during the current transaction.

A提交表示当前事务中所做的更改是永久性的,并对其他会话可见。另一方面,rollback语句取消当前事务所做的所有修改。提交和回滚释放在当前事务期间设置的所有innodb锁。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值