Menu Close

Drop MySQL Database

Drop MySQL Database

In this article, we are going to learn all about How to drop MySQL databases using the MySQL DROP DATABASE statement. In the previous tutorial, we have seen all about, how to create a MySQL database.

MySQL DROP Database Statement

MySQL provides a DROP DATABASE statement to delete the data database from the MySQL server. DROP DATABASE drops all the databases from the MySQL server Therefore, you need to be very careful when you are going to work with the MySQL DROP DATABASE statement.

Syntax

The syntax of MySQL DROP DATABASE statement is:-

DROP DATABASE [IF EXIST] database_name;

If you try to delete a database that does not exist, MySQL cause an error. To prevent an error from occurring if you deleting the non-existing database, you have to use the IF EXIST statement before the database name.

The DROP DATABASE statement returns the number of tables deleted.

You can use DROP SCHEMA instead of DROP DATABASE because SCHEMA is the synonym of DATABASE.
You can see the following syntax.

DROP SCHEMA [IF EXIST] database_name;

There are two ways to drop databases from the MySQL server.

  1. Using MySQL Client tool.
  2. Using Workbench

MySQL DROP DATABASE using mysql client tool

Here we will see step by step guide to dropping the database from the MySQL server using the MySQL client tool.

Let’s get started:

  • Open your MySQL client tool and loging from following command.
sudo mysql -u root -p 

After issuing the above command, MySQL will give a prompt to enter the root password.

if you are using a windows machine, Then you can directly open the MySQL client tool and enter a password.

  • Now, display all the existing databases from the MySQL server using SHOW DATABASES command.
mysql> SHOW DATABASES;

MySQL will give you output like below.


+--------------------+
| Database           |
+--------------------+
| college            |
| demodb             |
| information_schema |
| mydb               |
| mysql              |
| mysqldjango        |
| performance_schema |
| sakila             |
| sys                |
| testdb             |
| testing            |
| world              |
+--------------------+
12 rows in set (0.00 sec)
  • Suppose we want to drop database named testing.To drop the database, we need to issue follosing command.
mysql> DROP DATABASE testing;

After issuing the above command, if you get the following message. That means Database testing has been deleted successfully.

Query OK, 0 rows affected (0.19 sec)

DROP DATABASE using MySQL Workbench

  • First, launch the MySQL workbench and login into MySQL server.
Create MySQL Database
  • Second, right click on database that you want to remove, Suppose we want to remove database testing.Right click on testing database and click on drop schema option.
drop mysql database
  • Third, MySQL workbench display a dialog box to confirm the deletion.
drop mysql database

If you choose Review SQL, you will see the SQL query that will be executed, and if you choose Drop Now, it will delete the database immediately.

Here we will choose Review SQL to be safe.

  • Once you are sure that SQL statement is going to drop the right database, You can click the Execute button to execute the statement.
drop mysql database
  • MySQL return the following output that indicate the database dropped successfully.
drop mysql database

Conclusion

So, in this article, we have seen all about how to DROP MySQL DATABASE using two ways.
You can choose any one of them to drop the database. I strongly recommend you, be careful before drop the MySQL database.

If you like this article, please keep visiting for further MySQL tutorials.

Reference:- Click Here

Previous Article
Next Article

Was this post helpful?

Related Posts