Home  >  Article  >  Database  >  How to delete database in MySQL

How to delete database in MySQL

coldplay.xixi
coldplay.xixiOriginal
2020-10-19 14:26:4810892browse

MySQL method of deleting a database: 1. Use the drop command to delete the database, the code is [drop database e5c249aa15ff4c64720f99bfaecf8a60;]; 2. Use the PHP script to delete, the code is [mysqli_query(connection,query, resultmode);].

How to delete database in MySQL

MySQL method to delete the database:

1. Drop command to delete the database

drop command format:

drop database <数据库名>;

For example, to delete a database named RUNOOB:

mysql> drop database RUNOOB;

2. Use mysqladmin to delete the database

You can also use the mysql mysqladmin command to execute the delete command in the terminal.

The following example deletes the database RUNOOB (the database has been created in the previous chapter):

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

After executing the above delete database command, a prompt box will appear to confirm whether the database is really 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 &#39;RUNOOB&#39; database [y/N] y
Database "RUNOOB" dropped

3. Use PHP script to delete the database

PHP uses the mysqli_query function to create or delete the MySQL database.

This function has two parameters and returns TRUE when executed successfully, otherwise it returns FALSE.

Syntax

mysqli_query(connection,query,resultmode);

Examples

The following examples demonstrate the use of the PHP mysqli_query function to delete the database:

Delete database

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

Related free learning recommendations: mysql database(Video)

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn