Autocommit

Autocommit and Implicit Commits

With autocommit=1, the default, every statement outside START TRANSACTION commits the moment it succeeds. After SET autocommit = 0, every statement joins an open transaction that lasts until you commit, so a forgotten session holds its locks and its snapshot indefinitely. Leave autocommit on and open transactions explicitly, as PDO and Laravel 2,157 do.

Many statements cause an implicit commit of the open transaction: all DDL (CREATE, ALTER, DROP, RENAME, TRUNCATE), account statements (CREATE USER, GRANT), LOCK TABLES, START TRANSACTION, SET autocommit = 1, and maintenance such as ANALYZE TABLE. CREATE TEMPORARY TABLE does not commit, but cannot be rolled back either. In a test session with autocommit off, UPDATE products SET price = 5.49 WHERE id = 8, then CREATE TABLE price_audit (id INT), then ROLLBACK left the price at 5.49: the CREATE had already committed it. Keep schema changes out of data transactions, and do not expect a failed migration to undo its earlier DDL: each statement is atomic, but a sequence of them is not (Creating Migrations).