0
votes

I'm confused with transaction and autocommit. But there's no documents explains what MySQL autocommit do.

If autocommit on, every INSERT UPDATE DELETE statement will take effect immediately. Does MySQL auto start a transaction to do this?

If not, what's MySQL do? What's the difference to transaction?

In my view:

A statement

INSERT INTO ...

with autocommit on equals to

START TRANSACTION;

INSERT INTO ...;

COMMIT;

with autocommit off.

The two statements in anytime any condition takes the same action.

Is it right?

1

1 Answers

0
votes

firstly, you have to know, that most MySQL Storage Engines do not support transactions. for example, InnoDB supports, but MyISAM - not.

In InnoDB, you can use transactions by 2 way:

  • implicit

    START TRANSACTION;
    INSERT/UPDATE/DELETE
    COMMIT;

  • explicit

via SET autocommit off

both of them provide the same result