Deletion method: 1. Use the "win r" key to open the "Run" window, enter "cmd", and press Enter 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 to delete all tables in the specified database and permanently delete the database. The "IF EXISTS" option is optional. Setting this option can prevent deletion of unused files. An error occurred while the database exists.
The operating environment of this tutorial: windows7 system, mysql8 version, 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.
In MySQL, when you need to delete a created database, you can use the DROP DATABASE
statement.
The 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 an error from occurring when deleting a database that does not exist, 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 you delete these With two databases, 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 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;
[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!