MySQL-Drop Database

Drop database in mysql

Quick Links


MySQL-Drop Database : We can drop/delete/remove a MySQL database quickly with the MySQL DROP DATABASE command. It will delete the database along with all the tables, indexes, and constraints permanently.

Therefore, we should have to be very careful while removing the database in MySQL because we will lose all the data available in the database. If the database is not available in the MySQL server, the DROP DATABASE statement throws an error.


Example:

[root@host]# mysqladmin -u root -p drop TUTORIALS

Enter password:******

This will give you a warning and it will confirm if you really want to delete this database or not.

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

Example

Try the following example to delete a database −

<html>

   <head>

      <title>Deleting MySQL Database</title>

   </head>

   

   <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 successfully\n";

         mysql_close($conn);

      ?>

   </body>

</html>

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *