To delete a database in MySQL or MariaDB, use the following Steps:
Contents
Step 1: Connect to your database server:
To begin, sign into MySQL with the following command:
1 2 |
[user@localhost $] mysql -u root -p Enter password: |
Enter the administrator password you set up during installation.
Step 2: Display a list of your available databases.
Enter the command SHOW DATABASES; to list all of the databases you have stored. Besides the database you just created.
1 2 3 4 5 6 7 8 9 10 11 12 |
mysql> mysql> SHOW DATABASES ; +--------------------------------+ | Database | +--------------------------------+ | information_schema | | mysql | | performance_schema | | tutorials_space_db | +--------------------------------+ 4 rows in set (0.01 sec)mysql> mysql> |
Step 3: Delete Your database:
To delete a database in MySQL or MariaDB, use the following command:
1 2 3 |
mysql> DROP DATABASE tutorials_space_db ; Query OK, 0 rows affected (0.00 sec) mysql> |
This operation cannot be reversed! Make certain you wish to delete before pressing enter!
If this command is executed on a database that does not exist, the following error message will be given:
1 2 3 |
mysql> DROP DATABASE tutorials_space_db ; ERROR 1008 (HY000): Can't drop database 'new_database'; database doesn't exist mysql> |
To prevent this error, and ensure that the command executes successfully regardless of if the database exists, call it with the following syntax:
1 2 3 |
mysql> DROP DATABASE IF EXISTS tutorials_space_db ; Query OK, 0 rows affected (0.00 sec) mysql> |
Conclusion
In this post, i have explained How to Delete a Database in MySQL and MariaDB.
If you have any questions or feedback, feel free to leave a comment.
As always, if you found this post useful, then click like and share it 🙂