MySQL Delete database command usage detailed

Source: Internet
Author: User
Tags mysql delete mysql delete database php script

Downloading deletes using cmd mode


Command: Drop Database < database name >

For example, to delete a database named Xhkdb

The code is as follows Copy Code

mysql> drop Database xhkdb;

Example 1: Delete a database that is already determined to exist

The code is as follows Copy Code
mysql> drop Database drop_database;
Query OK, 0 rows Affected (0.00 sec)

Example 2: Delete a database with an indeterminate existence

  code is as follows copy code

   mysql> drop database drop_database;
   ERROR 1008 (HY000): Can ' t drop database ' drop_database '; Database doesn ' t exist
     //An error occurred and the ' drop_database ' database could not be deleted.
   mysql> drop database if exists drop_database;
   Query OK, 0 rows affected, 1 Warning (0.00 sec)//generates a warning stating that this database does not exist
   mysql> Create Datab ASE Drop_database;
   Query OK, 1 row Affected (0.00 sec)
   mysql> drop database if exists drop_database;//i F exists to determine whether the database exists, does not exist, and does not produce errors
   Query OK, 0 rows Affected (0.00 sec)


To Delete a database using mysqladmin:

Special permissions are required to create or delete a MySQL database. Therefore, suppose that you can use the MySQL mysqladmin binary to create any database as root user access.

Be careful to delete any database because it loses all the data available in the database.

This is the example to delete a database created in previous chapter:

[root@host]# mysqladmin-u root-p Drop Tutorials
Enter password:******
Here is an example of deleting a database in the previous section:

Dropping the "database is" potentially a very bad thing todo.
Any data stored in the database would be destroyed.

Do your really want to drop the ' tutorials ' database [y/n] Y
Database "Tutorials" dropped


PHP script deletes database:

PHP uses the Mysql_query function to create or delete a MySQL database. This function has two parameters and returns False if it returns TRUE or fails successfully.

Example:
BOOL mysql_query (SQL, connection);

Parameter description

Parameters Description
Sql Required-sql query to create or delete a MySQL database
Connection Optional-if not specified then last opened connection by mysql_connect'll be used.

Example:
Try the following example to delete a database:

The code is as follows Copy Code
<title>deleting MySQL database-by www.yiibai.com</title>
<body>
<?php
$dbhost = ' localhost:3036 ';
$dbuser = ' root ';
$dbpass = ' Rootpassword ';
$conn = mysql_connect ($dbhost, $dbuser, $dbpass);
if (! $conn)
{
Die (' Could not connect: '. Mysql_error ());
}
Echo ' Connected successfully<br/> ';
$sql = ' DROP DATABASE tutorials ';
$retval = mysql_query ($sql, $conn);
if (! $retval)
{
Die (' could not delete database: '. mysql_error ());
}
echo "Database tutorials deleted Successfullyn";
Mysql_close ($conn);
?>
</body>

Warning: When you delete a database and use PHP script, it will not prompt for any confirmation. So be careful to delete a MySQL database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.