Delete MySQL database (DROP DATABASE statement)

In MySQL, when you need to delete a database has been created, you can use  DROP DATABASE  or  DROP SCHEMA  statement. The syntax is:

 

DROP DATABASE [IF EXISTS] <database name>

Syntax is as follows:

  • <Database name>: the name of the database you want to delete.
  • IF EXISTS: to prevent errors when the database does not exist.
  • DROP DATABASE: Delete all tables in the database and delete the database. Be very careful when using this statement, so as not to be deleted by mistake. To use DROP DATABASE, DROP database need to get permission.

Note: After MySQL installation, the system will automatically create a database called the two systems information_schema and mysql, the database system and database to store some relevant information, if you delete these two databases, MySQL will not work properly.

Delete MySQL database instance

Test_db_del below to create a test database in MySQL.

  mysql> CREATE DATABASE test_db_del;  Query OK, 1 row affected (0.08 sec)  mysql> SHOW DATABASES;  +--------------------+  | Database           |  +--------------------+  | information_schema |  | mysql              |  | performance_schema |  | sakila             |  | sys                |  | test_db            |  | test_db_char       |  | test_db_del        |  | world              |  +--------------------+  9 rows in set (0.00 sec)

Guess you like

Origin blog.csdn.net/mysqlsd/article/details/103652927