Transactions

MySQL Transactions

Transaction statements are: START TRANSACTION, BEGIN, COMMIT, ROLLBACK and SET.

To start a new transaction uses the keyword START TRANSACTION or BEGIN.
COMMIT is used to make the current transaction changes.
ROLLBACK is used to cancel the current transaction changes.
SET autocommit disables or enables autocommit mode for the current session. By default, the autocommit mode is enabled.

MySQL Transaction syntax

START TRANSACTION
[ WITH CONSISTENT SNAPSHOT
| READ WRITE
| READ ONLY
]
BEGIN
COMMIT
ROLLBACK
SET autocommit = { 0 | 1 }

Transaction example

START TRANSACTION;
UPDATE test SET name='tom' WHERE id=1;
COMMIT;
ROLLBACK;