We learned how to create a database in MySQL in our earlier post but we didn't discuss how to delete an existing database in MySQL.
So in this post let's discuss everything about deleting an existing database in MySQL.
The general syntax to delete a database in MySQL is
DROP DATABASE [IF EXISTS] database_name;
Note: Syntax within square brackets is optional.
where,
IF EXISTSensures that MySQL does not throw an error if the database doesn't exist.database_nameis the name of the database.
Alternatively, you can also use the following syntax to delete a MySQL database
DROP SCHEMA [IF EXISTS] database_name;
because according to MySQL Glossary
Physically, a schema is synonymous with a database. You can substitute the keyword
SCHEMAinstead ofDATABASEin MySQL SQL syntax, for example usingCREATE SCHEMAinstead ofCREATE DATABASE.
Let's see some examples for a better understanding.
Example
First, let's list all the available databases using SHOW DATABASE; statement.

Now let's try deleting the 'programmerdb' database using the DROP statement which we have learned before.
DROP DATABASE programmerdb;
Result:

As a result of executing the DROP DATABASE statement, we get the number of rows affected. In our case, it is 1 which means that the 'programmerdb' database had only 1 table in it.
And if we list the database once again using SHOW DATABASE; statement, we notice 'programmerdb' is no longer available.
That's all for this small tutorial. I hope now you can easily delete an existing database in MySQL using the DROP DATABASE statement. If you have any doubts or suggestions then please comment below.