似乎您可以只使用 BEGIN 来实现您需要的所有事务;回滚和提交;。是否有某些场景需要使用自动提交?是否调用 BEGIN;将自动提交设置为假?调用 COMMIT;将自动提交设置为真?
最佳答案
可以为每个 session 或全局设置自动提交。没有需要自动提交的场景(并非所有 RDMS 都支持自动提交模式)。在我看来,默认情况下自动提交和 true 的原因是因为 MyISAM 引擎根本不支持事务,因此为了减轻为 MyISAM 编写的移植应用程序,它们模仿相同的行为。
Does calling BEGIN; set autocommit to false? Does calling COMMIT; set autocommit to true?
To disable autocommit mode for a single series of statements, use the START TRANSACTION statement: ...
With START TRANSACTION, autocommit remains disabled until you end the transaction with COMMIT or ROLLBACK. The autocommit mode then reverts to its previous state.
关于mysql - 使用 MySQL,如何开始;回滚;并提交;与自动提交有关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9643738/