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:

  1. Log into your database server using the MySQL or MariaDB client.
    $ mysql -u username -p
    Enter password:
  2. List all available databases.
    SHOW DATABASES;
    
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | exampledb          |
    | test               |
    +--------------------+
  3. Identify the database you want to delete.

    Ensure you are targeting the correct database for deletion.

  4. Delete the database using the DROP DATABASE command.
    DROP DATABASE exampledb;

    This operation is irreversible. All data in the database will be permanently removed.

  5. 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.

  6. Exit the MySQL or MariaDB client.
    EXIT;
Discuss the article:

Comment anonymously. Login not required.