4.2.7. MySQL deletes the database

发布时间 :2025-10-25 12:31:23 UTC      

Using ordinary users to log in to the MySQL server, you may need specific permissions to create or delete MySQL databases, so we use root users to log in, and root users have the highest permissions.

Be careful when deleting a database, because all data will disappear after the delete command is executed.

Drop command to delete database

Drop command format:

drop database <数据库名>;

For example, delete a database named RUNOOB:

mysql> drop database RUNOOB;

Delete a database using mysqladmin

You can also use it. mysql mysqladmin The command executes the delete command at the terminal.

The following example deletes the database RUNOOB (which was created in the previous section):

[root@host]# mysqladmin -u root -p drop RUNOOB
Enter password:******

After executing the above delete database command, a prompt box appears to confirm that the database is actually deleted:

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 'RUNOOB' database [y/N] y
Database "RUNOOB" dropped

Use the PHP script to delete the database

PHP usage mysqli_query Function to create or delete an MySQL database.

This function takes two arguments and returns TRUE on successful execution, or FALSE otherwise.

Grammar

mysqli_query(connection,query,resultmode);

Parameters.

Description

connection

Necessary. Specifies the MySQL connection to be used.

query

Required, specify the query string.

resultmode

Optional. A constant. It can be any of the following values:

  • MYSQLI_USE_RESULT(如果需要检索大量数据,请使用这个)

  • MYSQLI_STORE_RESULT(默认)

Example

The following example demonstrates the use of PHP mysqli_query Function to delete the database:

Delete database

<?php$dbhost='localhost';//mysql服务器主机地址$dbuser='root';//mysql用户名$dbpass='123456';//mysql用户名密码$conn=mysqli_connect($dbhost,$dbuser,$dbpass);if(!$conn){die('连接失败:'.mysqli_error($conn));}echo'连接成功<br
/>';$sql='DROP DATABASE
RUNOOB';$retval=mysqli_query($conn,$sql);if(!$retval){die('删除数据库失败:'.mysqli_error($conn));}echo"数据库
RUNOOB 删除成功\\n";mysqli_close($conn);?>

After successful execution, the results are as follows:

Image0

注意: When using the PHP script to delete the database, there will be no confirmation of whether to delete the information, but will delete the specified database directly, so you should be very careful when deleting the database.

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.