DROP TABLESPACE tablespace_name [ENGINE [=] engine_name]
This statement drops a tablespace that was previously created
CREATE TABLESPACE. It is
supported by the
InnoDB storage engines.
ENGINE sets the storage engine that uses the
engine_name is the
name of the storage engine. Currently, the values
supported. If not set, the value of
default_storage_engine is used.
If it is not the same as the storage engine used to create the
DROP TABLESPACE statement
case-sensitive identifier in MySQL.
InnoDB tablespace, all tables must be
dropped from the tablespace prior to a
TABLESPACE operation. If the tablespace is not empty,
DROP TABLESPACE returns an error.
NDB tablespace to be dropped must not
contain any data files; in other words, before you can drop an
NDB tablespace, you must first drop each of its
data files using
... DROP DATAFILE.
InnoDBtablespace is not deleted automatically when the last table in the tablespace is dropped. The tablespace must be dropped explicitly using
DROP DATABASEoperation 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 using
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 new
InnoDBdata. Space is not released back to the operating system as it is for file-per-table tablespaces.
This example demonstrates how to drop an
general tablespace. The general tablespace
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; Query OK, 0 rows affected (0.01 sec) mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE ts10 Engine=InnoDB; Query OK, 0 rows affected (0.02 sec) mysql> DROP TABLE t1; Query OK, 0 rows affected (0.01 sec) mysql> DROP TABLESPACE ts1; Query OK, 0 rows affected (0.01 sec)
This example shows how to drop an
myts having a data file named
mydata-1.dat after first creating the
tablespace, and assumes the existence of a log file group named
Section 13.1.16, “CREATE LOGFILE GROUP Syntax”).
mysql> CREATE TABLESPACE myts -> ADD DATAFILE 'mydata-1.dat' -> USE LOGFILE GROUP mylg -> ENGINE=NDB;
You must remove all data files from the tablespace using
ALTER TABLESPACE, as shown here,
before it can be dropped:
mysql> ALTER TABLESPACE myts -> DROP DATAFILE 'mydata-1.dat' -> ENGINE=NDB; mysql> DROP TABLESPACE myts;