MySQL (7) --- delete the database

 

Use ordinary user login MySQL server, you may need special permissions to create or delete MySQL database, so here we logged in as root, root user has the highest authority.

In the process of deleting the database, it is important to be very careful, because after the delete command, all data will be lost.

 

drop command to delete the database

drop command format:

drop database <database name>;

For example, to delete a database named RUNOOB:

mysql> drop database RUNOOB;

Delete the database using mysqladmin

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

The following examples delete database RUNOOB (the database has been created in the previous section):

 

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

After these steps to delete the database command, there will be a prompt box to confirm it really delete the database:

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 PHP script to remove the database

Mysqli_query use PHP functions to create or delete MySQL database.

This function takes two arguments and returns TRUE if executed successfully, otherwise it returns FALSE.

grammar

mysqli_query(connection,query,resultmode);
parameter description
connection essential. MySQL provisions connection to use.
query Essential provisions of the query string.
resultmode

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

  • MYSQLI_USE_RESULT (If you need to retrieve large amounts of data, use this)
  • MYSQLI_STORE_RESULT (default)

Examples

The following example illustrates the use of PHP mysqli_query function to delete the database:

Delete Database

<?php
$dbhost = 'localhost:3306';  // 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 the successful implementation, the number of results is:

Note:  When using PHP script to delete the database, does not appear to confirm whether to delete a message, just delete the specified database, so when you delete a database to be especially careful.

Guess you like

Origin blog.csdn.net/zhangbijun1230/article/details/92377413