Home  >  Article  >  Database  >  How to delete database in mysql

How to delete database in mysql

青灯夜游
青灯夜游Original
2022-01-06 16:22:5732715browse

In mysql, you can use the "DROP DATABASE" statement to delete the database. The specific syntax format is "DROP DATABASE [IF EXISTS] database name;"; the optional clause "IF EXISTS" is used to prevent An error occurred when the database does not exist.

How to delete database in mysql

The operating environment of this tutorial: windows10 system, mysql8 version, Dell G3 computer.

Mysql method of deleting a database

Deleting a database means that all data and associated objects in the database will be permanently deleted and cannot be undone. Therefore, it is very important to perform this query with additional considerations.

To drop a database, use the DROP DATABASE statement as follows:

DROP DATABASE [IF EXISTS] 数据库名;

Follow DROP DATABASE is the name of the database to be dropped. Similar to the CREATE DATABASE statement, IF EXISTS is an optional part of the statement to prevent an error when you delete a database that does not exist in the database server.

If you want to practice using the DROP DATABASE statement, you can create a new database and then delete it. Let’s look at the following query:

CREATE DATABASE IF NOT EXISTS tempdb;
SHOW DATABASES;
DROP DATABASE IF EXISTS tempdb;

The description of the three statements is as follows:

  • First, use the CREATE DATABASE statement to create a file named tempdb database.

  • Second, use the SHOW DATABASES statement to display all databases.

  • Third, use the DROP DATABASE statement to delete the database named tempdb.

[Related recommendations: mysql video tutorial]

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!

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