Home > Database > Mysql Tutorial > How to delete database in MySQL

How to delete database in MySQL

coldplay.xixi
Release: 2020-10-19 14:26:48
Original
10936 people have browsed it

MySQL method of deleting a database: 1. Use the drop command to delete the database, the code is [drop database ;]; 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 <数据库名>;
Copy after login

For example, to delete a database named RUNOOB:

mysql> drop database RUNOOB;
Copy after login

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:******
Copy after login

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
Copy after login

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);
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template