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);].
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 'RUNOOB' 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 = '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); ?>
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!