Home > Common Problem > How to delete database in MySQL

How to delete database in MySQL

百草
Release: 2023-06-14 14:42:51
Original
22706 people have browsed it

MySQL method to delete the database: 1. Use the "win r" key to open the "Run" window, enter "cmd" to enter the cmd command window; 2. In the cmd window, execute "mysql -u root - p" command to log in to the MySQL server; 3. Execute the "DROP DATABASE IF EXISTS database name;" command. This command is used to permanently delete all tables in the specified database.

How to delete database in MySQL

The operating system of this tutorial: Windows 10 system, mysql version 8.0, Dell G3 computer.

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. The "IF EXISTS" option is optional and can be set to prevent errors when deleting a database that does not exist.

In MySQL, when you need to delete a created database, you can use the DROP DATABASE statement.

DROP DATABASE statement deletes all tables in the database and permanently deletes the database. Therefore, you should be very careful when using this statement.

The following shows the syntax of the DROP DATABASE statement:

DROP DATABASE [IF EXISTS] 数据库名;
Copy after login

In this statement, specify the name of the database to be dropped.

MySQL will issue an error if you try to delete a database that does not exist.

To prevent errors from occurring when deleting a non-existent database, you can use the IF EXISTS option. In this case, MySQL terminates the statement without issuing any error.

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 these two databases are deleted, MySQL will not work properly. .

DROP DATABASE statement to delete the database example:

1. Use the "win r" key to open the "Run" window, enter "cmd", and press Enter to enter the cmd command window

How to delete database in MySQL

How to delete database in MySQL

How to delete database in MySQL

2. Log in to the MySQL server as the root user. Note that you can use your own database user instead of root.

mysql -u root -p
Enter password: ********
Copy after login

How to delete database in MySQL

Use the SHOW DATABASES statement to view all existing databases in the server:

SHOW DATABASES;
Copy after login
Copy after login

3. Use the DROP DATABASE statement to delete the database (test_db_del1 and test_db_del2)

How to delete database in MySQL

DROP DATABASE test_db_del1;
DROP DATABASE test_db_del2;
Copy after login

How to delete database in MySQL

SHOW DATABASES;
Copy after login
Copy after login

How to delete database in MySQL

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