是否可以回滚所有在同一个连接线程中执行过的语句?而不是 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/