1. 在Mysql中,当需要删除已创建的数据库时,可以使用drop database 语句,其语法格式为:
drop database [if exists] <数据库名>
语法说明如下:
* <数据库名>:指定要删除的数据名
* if exists:用于防止当数据库不存在时发生错误
* drop database:删除数据库中的所有表格并同时删除数据库。使用此语句时要非常小心,以免错误删除,如果要使用drop database,需要获得数据库drop权限。
注意:Mysql安装后,系统会自动创建名为information_schema和mysql的两个系统数据库,系统数据库存放一些和数据库相关的信息, 如果删除了这两个数据库,mysql将不能正常工作。
实例1:
1. 下面在mysql中创建一个测试数据库test_db_del
2. 使用命令行工具将数据库test_db_del从数据库列表中删除,输入的sql语句如下所示(结果省略):
create database if not exists test_db_del
drop database if exists test_db_del