DROP {DATABASE | SCHEMA} [IF EXISTS] db_name
DROP DATABASE 丢弃数据库中的所有表并删除数据库。Be 非常小心使用此语句!要使用 DROP DATABASE,你需要数据库上的 DROP 权限。DROP
SCHEMA 是 DROP
DATABASE“。DROP DATABASE drops all tables in
the database and deletes the database. Be
very careful with this statement! To use
DROP DATABASE, you need the
DROP privilege on the database.
DROP
SCHEMA is a synonym for DROP
DATABASE.
当数据库被丢弃时,专门为该数据库授予的权限不会自动丢弃。这些权限必须手动丢弃。参见 第 15.7.1.6 节,”GRANT Statement“。When a database is dropped, privileges granted specifically for the database are not automatically dropped. They must be dropped manually. See Section 15.7.1.6, “GRANT Statement”.
IF EXISTS用于防止数据库不存在时的错误发生。IF EXISTS is used to prevent an error from
occurring if the database does not exist.
如果默认数据库被删除,默认数据库将被取消设置(DATABASE() 函数返回 NULL)。If the default database is dropped, the default database is unset
(the DATABASE() function returns
NULL).
如果你在符号链接数据库上使用 DROP DATABASE,链接和原始数据库都会被删除。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 语句会从指定的数据库目录中移除 MySQL 在正常操作期间可能创建的文件和目录。这包括所有具有以下扩展名的文件:The DROP DATABASE statement removes
from the given database directory those files and directories that
MySQL itself may create during normal operation. This includes all
files with the extensions shown in the following list:
.BAK.DAT.HSH.MRG.MYD.MYI.cfg.db.ibd.ndb
如果在 MySQL 删除上述文件后数据库目录中仍有其他文件或目录,则无法删除数据库目录。在这种情况下,你必须手动删除剩余的文件或目录,然后再次执行 DROP DATABASE 语句。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.
删除数据库不会移除在该数据库中创建的任何 TEMPORARY 临时表。TEMPORARY 临时表会在创建它们的会话结束时自动删除。参见 第 15.1.20.2 节,“CREATE TEMPORARY TABLE 语句”。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 15.1.20.2, “CREATE TEMPORARY TABLE Statement”.
你也可以使用 mysqladmin 删除数据库。参见 第 6.5.2 节,“mysqladmin — MySQL 服务器管理程序”。You can also drop databases with mysqladmin. See Section 6.5.2, “mysqladmin — A MySQL Server Administration Program”.