Drop Database In MySQL Database

You can create/drop any database using MySQL mysqladmin binary. It’s very important to understand that If you drop a database, that means to delete any database then all the data in it will be deleted forever.So always think twice before dropping a database.

Here is an example to Drop Database In MySQL Database in the previous chapter:

[root@host]# mysqladmin -u root -p drop  Database tutorials

Enter password:******

 

First of all, this will provide a warning and it will confirm if you really want to delete this database or “no”.

Any data stored in the database will be destroyed.

 

Do you really want to drop the ‘ Database tutorials‘ database [y/N] y

Database ” Database tutorials” dropped

Drop Database using PHP Script:

PHP uses the mysql_query function in order  to either  create or delete a MySQL database.

Syntax:

bool mysql_query( sql, connection );

 

CommandDetail
sqlRequired – SQL query either to create or delete a MySQL database
connectionOptional – if not specified, then last opened connection will be used by  mysql_connect.

Example:

An example to delete a database:

 

[php]





‘;
$sql = ‘DROP DATABASE TUTORIALS’;
$result = mysql_query( $sql, $con );
if(! $result )
{
die(‘Could not delete database: ‘ . mysql_error());
}
echo “Database TUTORIALS deleted successfully\n”;
mysql_close($con);
?>

[/php]

Related Article

Leave a Comment