13.1.24 DROP DATABASE Statement语句

DROP {DATABASE | SCHEMA} [IF EXISTS] db_name

DROP DATABASE drops all tables in the database and deletes the database. DROP DATABASE删除数据库中的所有表并删除数据库。Be very careful with this statement! 使用这句语句要非常小心!To use DROP DATABASE, you need the DROP privilege on the database. 要使用DROP DATABASE,您需要对数据库具有DROP权限。DROP SCHEMA is a synonym for DROP DATABASE.DROP SCHEMADROP DATABASE的同义词。

Important重要

When a database is dropped, privileges granted specifically for the database are not automatically dropped. 删除数据库时,不会自动删除专门为该数据库授予的权限。They must be dropped manually. 必须手动删除它们。See Section 13.7.1.6, “GRANT Statement”.请参阅第13.7.1.6节,“GRANT语句”

IF EXISTS is used to prevent an error from occurring if the database does not exist.IF EXISTS用于防止数据库不存在时发生错误。

If the default database is dropped, the default database is unset (the DATABASE() function returns NULL).如果删除默认数据库,则默认数据库未设置(DATABASE()函数返回NULL)。

If you use DROP DATABASE on a symbolically linked database, both the link and the original database are deleted.如果在符号链接的数据库上使用DROP DATABASE,则链接和原始数据库都将被删除。

DROP DATABASE returns the number of tables that were removed.DROP DATABASE返回已删除的表数。

The DROP DATABASE statement removes from the given database directory those files and directories that MySQL itself may create during normal operation. DROP DATABASE语句从给定的数据库目录中删除MySQL在正常操作期间可能创建的文件和目录。This includes all files with the extensions shown in the following list:这包括扩展名如下列表所示的所有文件:

If other files or directories remain in the database directory after MySQL removes those just listed, the database directory cannot be removed. 如果MySQL删除了刚才列出的文件或目录后,其他文件或目录仍保留在数据库目录中,则无法删除数据库目录。In this case, you must remove any remaining files or directories manually and issue the DROP DATABASE statement again.在这种情况下,必须手动删除所有剩余的文件或目录,然后再次发出DROP DATABASE语句。

Dropping a database does not remove any TEMPORARY tables that were created in that database. 删除数据库不会删除在该数据库中创建的任何TEMPORARY表。TEMPORARY tables are automatically removed when the session that created them ends. 创建TEMPORARY表的会话结束时,会自动删除它。See Section 13.1.20.2, “CREATE TEMPORARY TABLE Statement”.请参阅第13.1.20.2节,“CREATE TEMPORARY TABLE语句”

You can also drop databases with mysqladmin. 您还可以使用mysqladmin删除数据库。See Section 4.5.2, “mysqladmin — A MySQL Server Administration Program”.请参阅第4.5.2节,“mysqladmin-一套MySQL服务器管理程序”