# # Show what happens during ALTER TABLE when an existing file # exists in the target location. # # Bug #19218794: IF TABLESPACE EXISTS, CAN'T CREATE TABLE, # BUT CAN ALTER ENGINE=INNODB # CREATE TABLE t1 (a SERIAL, b CHAR(10)) ENGINE=Memory; INSERT INTO t1(b) VALUES('one'), ('two'), ('three'); # # Create a read-only file called MYSQLD_DATADIR/test/t1.ibd # Directory listing of test/*.ibd # t1.ibd ALTER TABLE t1 ENGINE = InnoDB; ERROR HY000: Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME' (errno: 184 - Tablespace already exists) ALTER TABLE t1 ENGINE = InnoDB; ERROR HY000: Got error 168 - 'Unknown (generic) error from engine' from storage engine # # Move the file to InnoDB as t2 # ALTER TABLE t1 RENAME TO t2, ENGINE = INNODB; SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( `a` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `b` char(10) DEFAULT NULL, UNIQUE KEY `a` (`a`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci SELECT * from t2; a b 1 one 2 two 3 three # # Try to rename t2 to t1 with an existing read-only t1 in the way. # ALTER TABLE t2 RENAME TO t1; ERROR HY000: Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME' (errno: 184 - Tablespace already exists) # # Try again but now with a read-only 'test' directory. # ALTER TABLE t2 RENAME TO t1; ERROR HY000: Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME' (errno: 184 - Tablespace already exists) # # Create another t1, but in the system tablespace. # SET GLOBAL innodb_file_per_table=OFF; CREATE TABLE t1 (a SERIAL, b CHAR(20)) ENGINE=InnoDB; INSERT INTO t1(b) VALUES('one'), ('two'), ('three'); SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `a` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `b` char(20) DEFAULT NULL, UNIQUE KEY `a` (`a`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci SELECT name, space=0 FROM information_schema.innodb_tables WHERE name = 'test/t1'; name space=0 test/t1 1 # # Try to move t1 from the system tablespace to a file-per-table # while a blocking read-only t1.ibd file exists. # # Move using innodb_file_per_table=ON # SET GLOBAL innodb_file_per_table=ON; # # Move using using innodb_file_per_table=ON and a read-only directory # ALTER TABLE t1 ADD COLUMN e1 INT, ALGORITHM=INPLACE; ALTER TABLE t1 ADD COLUMN e2 INT, ALGORITHM=COPY; # # Move using TABLESPACE=innodb_file_per_table # SET GLOBAL innodb_file_per_table=OFF; ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=INPLACE; ERROR HY000: Got error 11 - 'InnoDB error' from storage engine ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=COPY; ERROR HY000: Got error 168 - 'Unknown (generic) error from engine' from storage engine # # Move using TABLESPACE=innodb_file_per_table with a read-only directory # ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=INPLACE; ERROR HY000: Got error 11 - 'InnoDB error' from storage engine ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=COPY; ERROR HY000: Got error 168 - 'Unknown (generic) error from engine' from storage engine # # ALTER TABLE t1 from system tablespace to general tablespace # CREATE TABLESPACE s1 ADD DATAFILE 's1.ibd'; ALTER TABLE t1 TABLESPACE s1; # # Try to move t1 from a general tablespace to a file-per-table # while a blocking read-only t1.ibd file exists. # ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=INPLACE; ERROR HY000: Tablespace 'test/t1' exists. ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=COPY; ERROR HY000: Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME' (errno: 184 - Tablespace already exists) # # Try again with a read-only 'test' directory. # ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=INPLACE; ERROR HY000: Got error 11 - 'InnoDB error' from storage engine ALTER TABLE t1 TABLESPACE=innodb_file_per_table, ALGORITHM=COPY; ERROR HY000: Got error 168 - 'Unknown (generic) error from engine' from storage engine # # Cleanup # DROP TABLE t1, t2; DROP TABLESPACE s1;