mysql - InnoDB - 回滚连接的所有事务

标签 mysql innodb

是否可以回滚所有在同一个连接线程中执行过的语句?而不是 ROLLBACK 只是恢复最后执行的语句。

最佳答案

取决于自动提交,默认情况下每个连接都被禁用。来自MySql Manual

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 13.2.12, “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.

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.

如果启用自动提交,则无法回滚语句,因为提交 是隐式的。

关于mysql - InnoDB - 回滚连接的所有事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2684865/

相关文章:

MySQL:并发插入

php - 使用 CASE 更新多行需要很长时间

mysql - 使用 MySQL 加速多表连接

mysql - InnoDB 磁盘使用开销

php - 通过 PHP 优化 MySQL InnoDB 插入

mysql - 多对多SQL select查询来获取匹配的记录

php - 命令 php echo 输出

performance - MySQL 查询多对多关系 : unions?

mysql - SQL 错误 : Row size too large for VARCHAR(20)

mysql - 如果实际内容长度非常有限,则在字符串列的前缀或整个列上创建索引之间的区别