In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
When a 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 disk space. After clearing, all data in the database will be deleted together.
In MySQL, you can use the DROP DATABASE statement when you need to delete a database that has already been created. The syntax is:
DROP DATABASE [ IF EXISTS ]
The syntax is explained as follows:
: Specifies the name of the database to delete.
IF EXISTS: Used to prevent errors when the database does not exist.
DROP DATABASE: Delete all tables in the database and delete the database at the same time. Use this statement very carefully to avoid deletion errors. If you want to use DROP DATABASE, you need to obtain DROP permissions on the database.
Note: After MySQL is installed, the system will automatically create two system databases named information_schema and mysql. The system database stores some information related to the database. If these two databases are deleted, MySQL will not work properly.
Example 1
Let's create a test database test_db_del in MySQL.
mysql> CREATE DATABASE test_db_del;Query OK, 1 row affected (0.08 sec)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. The SQL statement entered and the execution result are as follows:
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)
The database test_db_del does not exist. Execute the same command again, directly using DROP DATABASE test_db_del, and the system will report an error, as follows:
mysql> DROP DATABASE test_db_del;ERROR 1008 (HY000): Can't drop database 'test_db_del'; database doesn't exist
If you use the IF EXISTS clause, you can prevent the system from reporting such errors, as follows:
mysql> DROP DATABASE IF EXISTS test_db_del;Query OK, 0 rows affected, 1 warning (0.00 sec)
Use caution when using the DROP DATABASE command, MySQL does not give any prompt confirmation after executing the command. When DROP DATABASE deletes a database, all tables and data stored in the database are deleted and cannot be restored. Therefore, it is best to backup the database before deleting it.
The above is the delete database command is what the details, more please pay attention to other related articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.