Does setting autocommit = 0 include in a transaction?

I am viewing code by another developer. It has a commit that explicitly adds set autocommit=0 at the start of the MySQL transaction. This causes problems for other non-transactional requests in the session.

Does set autocommit=0 anything to the transaction for this transaction? I assume this is not the case, as transactions implicitly do this anyway.

[The only rationale I can come up with for this commit might have been the one used by MySam (compared to the current InnoDB), and was it a way to simulate transactions in the first?]

+2
source share
2 answers

If a transaction is active, it is not affected by SET autocommit = 0 .

Otherwise, if the previous autocommit value was 1 , SET autocommit = 0 starts a new transaction.

If you use MariaDB and you are in doubt, you can check the in_transaction variable.

+2
source

From MySQL Reference :

After disabling autodiscover by setting the autocommit variable to zero, changes to transaction-safe tables (for example, for InnoDB or NDB) do not immediately become permanent. You must use COMMIT to store your changes to disk or ROLLBACK to ignore the changes.

Setting autocommit=0 will change the entire session. Transactions and non-transactional teams must be explicitly designed to impact the database.

+1
source

All Articles