Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rollback in the MySQL shell not working after ALTER TABLE

Tags:

mysql

innodb

(MySQL 5.5, InnoDB tables) Why can't I rollback, either to a savepoint or to the previous begin statement?

mysql> set autocommit=0;
Query OK, 0 rows affected (0.00 sec)

mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)

mysql> savepoint id;
Query OK, 0 rows affected (0.00 sec)

mysql> alter table sg_Section add column (published tinyint(1) default 0);
Query OK, 2 rows affected (0.30 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> rollback to savepoint id;
ERROR 1305 (42000): SAVEPOINT id does not exist

When not running any command after the savepoint, it seems to «work»:

mysql> savepoint id;
Query OK, 0 rows affected (0.00 sec)

mysql> rollback to savepoint id;
Query OK, 0 rows affected (0.00 sec)
like image 306
Simon A. Eugster Avatar asked Nov 18 '12 10:11

Simon A. Eugster


1 Answers

DDL is not transactional in MySQL.

Any DDL statement implicitly commits the open transaction.

More details in the manual: http://dev.mysql.com/doc/refman/5.5/en/implicit-commit.html

like image 199
a_horse_with_no_name Avatar answered Nov 16 '22 06:11

a_horse_with_no_name