Home >Database >Mysql Tutorial >What is the command to delete a database?
The command to delete the database is "DELETE DATA", the specific format is "DROP DATABASE [IF EXISTS] database name;", you can delete all tables in the database and delete the database at the same time. If you want to use "DROP DATABASE", you need to obtain the database DROP permission.
#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.
(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 ] 数据库名
The syntax description is as follows:
Database name: 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.
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.
Example:
View the database
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sakila | | sys | | test_db | | test_db_char | | test_db_del | | world | +--------------------+ 9 rows in set (0.00 sec)
Use the command line tool to delete the database test_db_del from the database list
mysql> DROP DATABASE test_db_del; Query OK, 0 rows affected (0.57 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sakila | | sys | | test_db | | test_db_char | | world | +--------------------+ 8 rows in set (0.00 sec)
At this time the database test_db_del is not exist.
For more programming-related knowledge, please visit: Programming Teaching! !
The above is the detailed content of What is the command to delete a database?. For more information, please follow other related articles on the PHP Chinese website!