Documentation Home
MySQL 9.3 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 261.1Kb
Man Pages (Zip) - 368.3Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.3 Reference Manual  / ...  / SQL Statements  / Data Definition Statements  /  DROP TABLESPACE Statement

15.1.36 DROP TABLESPACE Statement

DROP [UNDO] TABLESPACEtablespace_name

This statement drops a tablespace that was previously created usingCREATE TABLESPACE. It is supported by theNDB andInnoDB storage engines.

TheUNDO keyword must be specified to drop an undo tablespace. Only undo tablespaces created usingCREATE UNDO TABLESPACE syntax can be dropped. An undo tablespace must be in anempty state before it can be dropped. For more information, seeSection 17.6.3.4, “Undo Tablespaces”.

tablespace_name is a case-sensitive identifier in MySQL.

For anInnoDB general tablespace, all tables must be dropped from the tablespace prior to aDROP TABLESPACE operation. If the tablespace is not empty,DROP TABLESPACE returns an error.

AnNDB tablespace to be dropped must not contain any data files; in other words, before you can drop anNDB tablespace, you must first drop each of its data files usingALTER TABLESPACE ... DROP DATAFILE.

Notes

  • A generalInnoDB tablespace is not deleted automatically when the last table in the tablespace is dropped. The tablespace must be dropped explicitly usingDROP TABLESPACEtablespace_name.

  • ADROP DATABASE operation can drop tables that belong to a general tablespace but it cannot drop the tablespace, even if the operation drops all tables that belong to the tablespace. The tablespace must be dropped explicitly usingDROP TABLESPACEtablespace_name.

  • Similar to the system tablespace, truncating or dropping tables stored in a general tablespace creates free space internally in the general tablespace.ibd data file which can only be used for newInnoDB data. Space is not released back to the operating system as it is for file-per-table tablespaces.

InnoDB Examples

This example demonstrates how to drop anInnoDB general tablespace. The general tablespacets1 is created with a single table. Before dropping the tablespace, the table must be dropped.

mysql> CREATE TABLESPACE `ts1` ADD DATAFILE 'ts1.ibd' Engine=InnoDB;mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE ts1 Engine=InnoDB;mysql> DROP TABLE t1;mysql> DROP TABLESPACE ts1;

This example demonstrates dropping an undo tablespace. An undo tablespace must be in anempty state before it can be dropped. For more information, seeSection 17.6.3.4, “Undo Tablespaces”.

mysql> DROP UNDO TABLESPACEundo_003;

NDB Example

This example shows how to drop anNDB tablespacemyts having a data file namedmydata-1.dat after first creating the tablespace, and assumes the existence of a log file group namedmylg (seeSection 15.1.18, “CREATE LOGFILE GROUP Statement”).

mysql> CREATE TABLESPACE myts    ->     ADD DATAFILE 'mydata-1.dat'    ->     USE LOGFILE GROUP mylg    ->     ENGINE=NDB;

You must remove all data files from the tablespace usingALTER TABLESPACE, as shown here, before it can be dropped:

mysql> ALTER TABLESPACE myts    ->     DROP DATAFILE 'mydata-1.dat';mysql> DROP TABLESPACE myts;