Home  >  Article  >  Database  >  What is the command to delete a database?

What is the command to delete a database?

青灯夜游
青灯夜游Original
2020-11-11 16:44:3928194browse

The command to delete the database is "DELETE DATA", the specific format is "DROP DATABASE [IF EXISTS] database name;", you can delete all tables in the database and delete the database at the same time. If you want to use "DROP DATABASE", you need to obtain the database DROP permission.

What is the command to delete a database?

#When the database is no longer in use, it should be deleted to ensure that valid data is stored in the database storage space. Deleting a database is to clear the existing database from the disk space. After clearing, all data in the database will also be deleted.

(Recommended tutorial: mysql video tutorial)

In MySQL, when you need to delete a created database, you can use the DROP DATABASE statement. The syntax format is:

DROP DATABASE [ IF EXISTS ] 数据库名

The syntax description is as follows:

  • Database name: Specify the name of the database to be deleted.

  • IF EXISTS: Used to prevent errors from occurring when the database does not exist.

  • DROP DATABASE: Delete all tables in the database and delete the database at the same time. Be very careful when using this statement to avoid mistaken deletions. If you want to use DROP DATABASE, you need to obtain database DROP permission.

Note: After MySQL is installed, the system will automatically create two system databases named information_schema and mysql. The system database stores some database-related information. If you delete these With two databases, MySQL will not work properly.

Example:

View the database

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)

Use the command line tool to delete the database test_db_del from the database list

mysql> DROP DATABASE test_db_del;
Query OK, 0 rows affected (0.57 sec)
mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| test_db            |
| test_db_char       |
| world              |
+--------------------+
8 rows in set (0.00 sec)

At this time the database test_db_del is not exist.

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of What is the command to delete a database?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn