数据定义语句(2)DROP DATABASE

删除数据库。语法规则如下:

DROP {DATABASE|SCHEMA} [IF EXISTS] db_name

执行 DROP DATABASE 会删除数据库里的所有表然后再删除数据库,所以执行这条语句的时候一定要慎重。要执行该语句,你需要拥有数据库的 DROP 权限。DROP SCHEMADROP DATABASE 可以互相替换。

特别注意: 当在删除数据库时,与数据库相关的授权信息不会被自动删除,这些信息必须手动删除。

当数据库不存在时,使用 IF EXISTS 来避免产生错误。

DROP DATABASE 的返回值删除的表的数量。

当删除内置的数据库时,只将数据库清空恢复到初始状态,不会真正执行删除操作。

注:引用部分大意是删除数据库时会删除哪些文件,这些与其他内容有关联,留到后面一起翻译。

If you use DROP DATABASE on a symbolically linked database, both the link and the original database
are deleted.

DROP DATABASE returns the number of tables that were removed. This corresponds to the number of
.frm files removed.
The DROP DATABASE statement removes from the given database directory those files and directories
that MySQL itself may create during normal operation:
• All files with the following extensions:
• .BAK
• .DAT
• .HSH
• .MRG
• .MYD
• .MYI
• .TRG
• .TRN
• .cfg
• .db
• .frm
• .ibd
• .ndb
• .par
• The db.opt file, if it exists.
If other files or directories remain in the database directory after MySQL removes those just listed, the
database directory cannot be removed. In this case, you must remove any remaining files or directories
manually and issue the DROP DATABASE statement again.
Dropping a database does not remove any TEMPORARY tables that were created in that database.
TEMPORARY tables are automatically removed when the session that created them ends. See
Section 13.1.18.3, “CREATE TEMPORARY TABLE Syntax”.
You can also drop databases with mysqladmin. See Section 4.5.2, “mysqladmin — Client for
Administering a MySQL Server”.

你可能感兴趣的:(数据定义语句(2)DROP DATABASE)