格式

    1. DROP DATABASE [IF EXISTS] dbname;

    DROPDATABASE 用于取消数据库中的所用表格和取消数据库。IF EXISTS用于防止当数据库不存在时发生错误。

    示例

    1. mysql> drop database notest;
    2. ERROR 1008 (HY000): Can't drop database 'notest'; database doesn't exist
    3. mysql> drop database if exists notest;
    4. Query OK, 0 rows affected, 1 warning (0.00 sec)
    5. mysql> show warnings;
    6. +-------+------+------------------------------------------------------+
    7. | Level | Code | Message |
    8. +-------+------+------------------------------------------------------+
    9. | Note | 1008 | Can't drop database 'notest'; database doesn't exist |
    10. +-------+------+------------------------------------------------------+
    11. 1 row in set (0.00 sec)

    报错

    • 语法错误时,报 ERROR 1064 (42000): You have an error in your SQL syntax;

    • 数据库不存在,报 ERROR 1008 (HY000): Can't drop database 'XXX'; database doesn't exist;