13.1.33 DROP TABLESPACE Statement语句

DROP [UNDO] TABLESPACE tablespace_name
    [ENGINE [=] engine_name]

This statement drops a tablespace that was previously created using CREATE TABLESPACE. 此语句删除以前使用CREATE TABLESPACE创建的表空间。It is supported by the NDB and InnoDB storage engines.它由NDB和InnoDB存储引擎支持。

The UNDO keyword, introduced in MySQL 8.0.14, must be specified to drop an undo tablespace. MySQL 8.0.14中引入的UNDO关键字必须指定才能删除UNDO表空间。Only undo tablespaces created using CREATE UNDO TABLESPACE syntax can be dropped. 只能删除使用CREATE UNDO TABLESPACE语法创建的撤销表空间。An undo tablespace must be in an empty state before it can be dropped. 撤消表空间必须处于EMPTY状态才能删除。For more information, see Section 15.6.3.4, “Undo Tablespaces”.有关更多信息,请参阅第15.6.3.4节,“撤消表空间”

ENGINE sets the storage engine that uses the tablespace, where engine_name is the name of the storage engine. ENGINE设置使用表空间的存储引擎,其中engine_name是存储引擎的名称。Currently, the values InnoDB and NDB are supported. 目前,支持InnoDBNDB值。If not set, the value of default_storage_engine is used. 如果未设置,则使用default_storage_engine的值。If it is not the same as the storage engine used to create the tablespace, the DROP TABLESPACE statement fails.如果它与用于创建表空间的存储引擎不同,DROP TABLESPACE语句将失败。

tablespace_name is a case-sensitive identifier in MySQL.tablespace_name是MySQL中区分大小写的标识符。

For an InnoDB general tablespace, all tables must be dropped from the tablespace prior to a DROP TABLESPACE operation. 对于InnoDB通用表空间,在执行DROP TABLESPACE操作之前,必须从表空间中删除所有表。If the tablespace is not empty, DROP TABLESPACE returns an error.如果表空间不是空的,DROP TABLESPACE将返回一个错误。

An 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 ALTER TABLESPACE ... DROP DATAFILE.要删除的NDB表空间不能包含任何数据文件;换句话说,在删除NDB表空间之前,必须首先使用ALTER TABLESPACE ... DROP DATAFILE删除其每个数据文件。

Notes

InnoDB ExamplesInnoDB示例

This example demonstrates how to drop an InnoDB general tablespace. 此示例演示如何删除InnoDB通用表空间。The general tablespace ts1 is created with a single table. 通用表空间ts1是使用单个表创建的。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 an empty state before it can be dropped. 撤消表空间必须处于empty状态才能删除。For more information, see Section 15.6.3.4, “Undo Tablespaces”.有关更多信息,请参阅第15.6.3.4节,“撤消表空间”

mysql> DROP UNDO TABLESPACE undo_003;

NDB ExampleNDB示例

This example shows how to drop an NDB tablespace myts having a data file named mydata-1.dat after first creating the tablespace, and assumes the existence of a log file group named mylg (see Section 13.1.16, “CREATE LOGFILE GROUP Statement”).此示例演示如何在首次创建表空间后删除具有名为mydata-1.dat的数据文件的NDB表空间myts,并假设存在名为mylg的日志文件组(请参阅第13.1.16节,“创建日志文件组语句”)。

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:必须使用ALTER TABLESPACE从表空间中删除所有数据文件,如下所示,然后才能删除:

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

mysql> DROP TABLESPACE myts;