MySQL transactions with schema modification statements (DDL)?

2.7k views Asked by At

Despite commit or rollback, the change is "commited" in both cases.

Commit:

START TRANSACTION;
ALTER TABLE `bank` CHANGE COLUMN `bank_active` `bank_activated` BOOLEAN NOT NULL;
COMMIT;

Rollback:

START TRANSACTION;
ALTER TABLE `bank` CHANGE COLUMN `bank_active` `bank_activated` BOOLEAN NOT NULL;
ROLLBACK;

Need to build an automatic updater, that includes database's schema and data updates, and would like to group everything into a transaction, so in case anything goes wrong, just fix the statements and run again.

Is it possible to rollback DDL statements within transactions?

Thank you

1

There are 1 answers

0
Rick James On BEST ANSWER

BEGIN in some contexts is the same as START TRANSACTION.

phpmyadmin performs one query at a time unless you put the batch in the window for such. Try that.

(And SET autocommit = 0 is irrelevant because of the explicit START.)

Edit

Since the "transaction" really had a DDL statement, my 'answer' is irrelevant.

DDLs cannot be rolled back: https://dev.mysql.com/doc/refman/5.7/en/cannot-roll-back.html