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.
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] 数据库名;
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
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: ********
Use the SHOW DATABASES statement to view all existing databases in the server:
SHOW DATABASES;
3. Use the DROP DATABASE statement to delete the database (test_db_del1 and test_db_del2)
DROP DATABASE test_db_del1; DROP DATABASE test_db_del2;
SHOW DATABASES;
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!