Recently we learned about how to create a database in MySQL. Now in this post, we will learn about how to delete database in MySQL. Deleting a database in MySQL is easy but keep in mind that you will lose all data which is stored in the MySQL database. So keep the practice of keeping a backup for your database before deleting it.
Table of Contents
How To Delete Database In MySQL
If you are a workbench user you can delete the MySQL database using workbench. In case you are a Linux user then you need to use a terminal to execute a command to drop or delete the MySQL database.
how to delete a database in MySQL workbench
- Launch workbench on your PC/laptop
- Login with the root user privilege.
- Now run the DROP DATABASE [IF EXISTS] database_name;
- In the above command, You determine the name of the database which you need to delete after the DROP DATABASE keywords.
how to delete a database in MySQL Linux
- Log into MySQL server using root user.
- Enter the root user password and press enter and do login.
- Now see all databases using the ‘show databases‘ command.
- Drop database using the ‘drop database‘ statement.
Be careful when you are going to delete your MySQL database because dropping or deleting the database will result in losing all information stored in the database. Also, keep in mind that you have admin privileges, otherwise you can’t delete database.
Select database carfully for delete. Beacuse once it deleted you can’t roll back you need to restore it’s backup to recreate that backup. So datbase name should be unique in the MySQL server instance. It will make your drop datbase statment more easy. All mysql versions have same command for drop/delete database so you don’t need worry about drop database command. Beacuse it remains same for all mysql versions.