When working with MariaDB or MySQL, it is common to manage multiple databases. Occasionally, it becomes necessary to delete a database that is no longer needed. Both MySQL and MariaDB use similar commands to handle database deletions due to their shared origins. Removing a database can be done quickly and effectively using the SQL DROP DATABASE command.
Deleting a database should be done carefully. The removal process is permanent, and all data contained in the database will be lost. Make sure that you do not need the data, and if there is any critical information, it should be backed up beforehand. This command will delete the database completely, so verify the database name before executing the deletion.
Once you're ready to proceed, ensure you are logged in as a user with the necessary privileges to delete databases. Using the SHOW DATABASES command helps confirm the database to be removed. After that, the database can be permanently deleted with the DROP DATABASE command. This process applies to both MariaDB and MySQL, making it straightforward for users of either system.
Steps to delete a database in MySQL and MariaDB:
- Log into your database server using the MySQL or MariaDB client.
$ mysql -u username -p Enter password:
- List all available databases.
SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | exampledb | | test | +--------------------+
- Identify the database you want to delete.
Ensure you are targeting the correct database for deletion.
- Delete the database using the DROP DATABASE command.
DROP DATABASE exampledb;
This operation is irreversible. All data in the database will be permanently removed.
- Verify that the database has been deleted by listing the databases again.
SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | test | +--------------------+
The deleted database should no longer appear in the list.
- Exit the MySQL or MariaDB client.
EXIT;
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.