Search code examples
mysqlmariadbcreate-tablerollback

MySQL / MariaDB does not rollback transaction


I am trying to make a transaction and then rollback afterwards.

My code is the following:

SET autocommit = OFF;
START TRANSACTION;
DROP TABLE IF EXISTS Test;
CREATE TABLE Test (test INT);
ROLLBACK;

However, even though I call ROLLBACK, the table Test will still be created.

The tables use InnoDB. I am using MariaDB version 10.3.15.


Solution

  • https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html

    ... The CREATE TABLE statement in InnoDB is processed as a single transaction. This means that a ROLLBACK from the user does not undo CREATE TABLE statements the user made during that transaction.