You would need special privilege to create or to delete a MySQL database. So assuming you have
access to root user, you can create any database using mysql mysqladmin binary.
Be careful while deleting any database because it will lose your all the data available in your
Here is an example to delete a database created in previous chapter:
[root@host]# mysqladmin -u root -p drop TUTORIALS
This will give you a warning and it will confirm if you really want to delete this database or
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 'TUTORIALS' database [y/N] y
Database "TUTORIALS" dropped
PHP uses mysql_query function to create or delete a MySQL database. This function takes
two parameters and returns TRUE on success or FALSE on failure.
bool mysql_query( sql, connection );
Try out following example to delete a database:
<title>Deleting MySQL Database</title>
$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 successfully\n";
WARNING: While deleting a database using PHP script, it does not prompt you for any
confirmation. So be careful while deleting a MySQL database.
Your Query was successfully sent!