Mysql 简明教程
MySQL - Drop Database
MySQL DROP Database Statement
MySQL 中的 DROP DATABASE 语句用于删除数据库以及所有数据,例如表、视图、索引、存储过程和约束。
The DROP DATABASE statement in MySQL is used to delete a database along with all the data such as tables, views, indexes, stored procedures, and constraints.
在删除现有数据库时 −
While deleting an existing database −
-
It is important to make sure that we have to perform the backup of the database that we are going to delete because once the "DROP DATABASE" statement is executed, all the data and database objects in the database will be permanently deleted and cannot be recovered.
-
It is also important to ensure that no other user or application is currently connected to the database that we want to delete. If we try to delete the database while others users are connected to it, then it can cause data corruption or other issues.
除了这些,在使用 DROP DATABASE 语句删除任何数据库之前,我们需要确保我们拥有必要的权限。
In addition to these we need to make sure we have the necessary privileges before deleting any database using the DROP DATABASE statement.
Syntax
以下是 MySQL 中删除数据库的语法 −
Following is the syntax to delete a database in MySQL −
DROP DATABASE DatabaseName;
此处,“DatabaseName” 是我们要删除的数据库的名称。
Here, the "DatabaseName" is the name of the database that we want to delete.
Example
首先,让我们使用以下查询在数据库系统中创建一个名为 TUTORIALS 的数据库 −
First of all, let us create a database named TUTORIALS into database system using the following query −
CREATE DATABASE TUTORIALS;
创建数据库后,执行以下查询以验证其是否创建 −
Once the database is created, execute the following query to verify whether it is created or not −
SHOW DATABASES;
正如我们在下面的数据库列表中所看到的,TUTORIALS 数据库已成功创建 −
As we can see the list of databases below, the TUTORIALS database has been created successfully −
现在,让我们使用以下 DROP DATABASE 语句删除 existing 数据库 <TUTORIALS> −
Now, let us delete the existing database <TUTORIALS> using the following DROP DATABASE statement −
DROP DATABASE TUTORIALS;
Dropping a Database using mysqladmin
您将需要特殊权限来创建或删除 MySQL 数据库。因此,假设您可以访问 root 用户,那么可以使用 mysql mysqladmin 二进制文件创建任何数据库。
You would need special privileges to create or to delete a MySQL database. So, assuming you have access to the root user, you can create any database using the mysql mysqladmin binary.
Note: 删除任何数据库时要小心,因为您将失去数据库中所有可用的数据。
Note: Be careful while deleting any database because you will lose your all the data available in your database.
Example
以下是一个示例,用于删除在上一个章节中创建的数据库 (TUTORIALS) −
Here is an example to delete a database(TUTORIALS) created in the previous chapter −
[root@host]# mysqladmin -u root -p drop TUTORIALS
Enter password:******
这将给您一个警告,它会要求您确认 (Y/N) 您是否真的想删除此数据库。如果您输入 'y',则数据库将被删除,否则不会删除 −
This will give you a warning and it will ask you to confirm (Y/N) that you really want to delete this database or not. If you enter 'y', the database will be deleted, else no −
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.
Do you really want to drop the 'TUTORIALS' database [y/N] y
Dropping Database Using a Client Program
除了使用 MySQL 查询来执行 DROP DATABASE 操作外,我们还可以使用 Node.js,PHP,Java 和 Python 等客户端程序来实现相同的结果。
Besides using MySQL queries to perform the DROP DATABASE operation, we can also use client programs like Node.js, PHP, Java, and Python to achieve the same result.