How to Drop MySQL database step by step guide for beginner


Mysql Drop Database | In this tutorial we learn how to Drop MySQL database on linux server using mysql promt , Drop MySQL database using MySQL workbench and php script also.

Drop MySQL database using mysql promt

Mysql Drop Database we require special privilege.To drop mysql database we are using root user and login the mysql server and execute the below command to drop mysql database through mysql promt.

If once database is deleted is not retrieve. So before deleting the database we need to take backup of the database for best practice.

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> drop database techrideradmin;
Query OK, 0 rows affected (0.07 sec)

After droping database we can list the databases using below command through mysql pomt.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)
Mysql Drop Database
How to Drop MySQL database on CentOS/RHEL/Oracle server step by step guide for beginner

Techrideradmin database has been dropped after executing the above command.




Drop MySQL database using mysql workbench

We can also DROP MySQL database using MySQL workbench also. To drop MySQL database using MySQL workbench  we need to follow the below method.

Step 1) First we need to login MySQL workbench using root privileges.

Step2) Secondly How many databases is present in our database list we need to review it. Then select the particular database which we need to drop.
Mysql database list,drop mysql database using mysql workbench
Mysql database list

Step3)now we are going to drop techrideradmin  which is present in our database list. Now we need to go the schema section at the left side and select the schema.Right click on the schema which we need to drop and then click on Drop schema option.

Step4) After clicking on the drop schema option we got a message to confirm that you want to drop the database permanently with its all existing data. Then press on drop now option to drop the database permanently from the database list.
Drop MySQL database using MySQL workbench
Drop MySQL database using MySQL workbench


Step 5) After executing the above task we got a output message in the output section that the database has been deleted successfully.
Output message DROP MySQL database, DROP MySQL database using mysql workbench
Output message DROP MySQL database
  

Drop MySQL database using php script.

We can drop mysql database using php script we use mysql_query function and two parameters need to be pass one is connection parameter which detect the conncetion is established or not and other is sql query.

Lets take an example to drop mysql database using php script.

<html>
   <head>
      <title>Drop MySQL database on linux system</title>
   </head>
   <body>
      <?php
         $mysql_host = 'localhost';
         $mysql_user = 'root';
         $mysql_pass = 'passwordofroot';
         $conn = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
        
         if(! $conn ) {
            die('Could not connect the server: ' . mysql_error());
         }
         echo 'Connection successfully established';
         $sql = 'DROP DATABASE techrideradmin';
         $result = mysql_query( $sql, $conn );
        
         if(! $result ) {
            die('Database could not drop: ' . mysql_error());
         }
         echo "Database techrideradmin Dropped successfully\n";
         mysql_close($conn);
      ?>
   </body>
</html>

That’s all.If this article is helpful to know about  Mysql Drop Database please share it!!!!


SHARE

Admin

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment