Home > Database > Mysql Tutorial > How to delete database in MySQL

How to delete database in MySQL

青灯夜游
Release: 2022-12-30 11:12:00
Original
39730 people have browsed it

Method: You can use the "DROP DATABASE" statement to delete the created database; the specific syntax is "DROP DATABASE [IF EXISTS] ;".

How to delete database in MySQL

The operating environment of this tutorial: Windows 7 system, mysql version 8.0.22, Dell G3 computer.

(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 ] <数据库名>;
Copy after login

The syntax description is as follows:

  • : 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.

Example:

Query the database list

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| test_db            |
| world              |
+--------------------+
7 rows in set (0.00 sec)
Copy after login

Delete the database test_db from the database list

mysql> DROP DATABASE test_db;
Query OK, 0 rows affected (0.57 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
6 rows in set (0.00 sec)
Copy after login

For more programming-related knowledge, please visit: programming video! !

The above is the detailed content of How to delete database in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template