This tutorial is part of the series Learn Basic SQL Queries Using MySQL. In this tutorial, we will discuss SQL queries to delete a database in MySQL.
Delete Query
The query DROP DATABASE can be used to drop all the tables and delete the database. It can be used as mentioned below. In case you are remotely logged in to the database, you will also need
Also, make sure that you have taken the backup of the database being dropped. Once dropped, it's very difficult to get back the data.
# To do - Delete Database # Query - DROP DATABASE <database name> # It might throw error in case database do not exist DROP DATABASE enterprise;
OR
# Good to go DROP DATABASE IF EXISTS enterprise;
Similar to the DROP DATABASE, you can also use DROP SCHEMA as shown below.
# To do - Delete Database # Query - DROP SCHEMA <database name> # It might throw error in case database do not exist DROP SCHEMA enterprise;
OR
# Good to go DROP SCHEMA IF EXISTS enterprise;
With the DROP DATABASE or DROP SCHEMA query, MySQL also deletes the files associated with the database being deleted having file extensions including .BAK, .DAT, .HSH, .MRG, .MYD, .MYI, .cfg, .db, .ibd, and .ndb.
This is how we can delete a database in MySQL using the SQL query.