Deleting an unused database keeps a MySQL or MariaDB server tidy, reduces accidental writes to the wrong schema, and can reclaim storage tied to old tables. A dropped database removes everything inside it, so the main value is clean removal with a clear, auditable action.
In MySQL and MariaDB, a database is a schema container for tables, views, triggers, routines, and events. The SQL statement DROP DATABASE performs a destructive DDL operation that removes the database metadata and all objects within that database. On servers with replication enabled, the statement is written to the binary log by default, so the deletion propagates to replicas.
The operation is permanent and cannot be rolled back with a transaction, so the target name and target server must be correct before running it. A backup via mysqldump is the fastest safety net for small-to-medium databases, while larger systems may require coordinated physical backups or snapshot-based workflows. If the account lacks privileges, errors like DROP command denied indicate missing DROP permissions for that schema.
Steps to delete a database in MySQL and MariaDB:
- Open a terminal with access to the database server.
- Log into the server using the mysql client.
$ mysql --user=username --password --host=db.example.net --port=3306 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. mysql>
For local socket access, omit --host and --port.
- Confirm the connected host and version details.
mysql> SELECT @@hostname AS host, @@port AS port, @@version AS version; +--------------+------+---------------------------+ | host | port | version | +--------------+------+---------------------------+ | db-example-1 | 3306 | 10.11.6-MariaDB-log | +--------------+------+---------------------------+ 1 row in set (0.00 sec)
- List databases to confirm the exact name to delete.
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | exampledb | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec)
- Create a SQL backup of the target database before deletion.
$ mysqldump --user=username --password --host=db.example.net --port=3306 --single-transaction --routines --events --databases exampledb > exampledb.sql
A missing backup turns a typo into a disaster.
- Delete the database using DROP DATABASE.
mysql> DROP DATABASE exampledb; Query OK, 0 rows affected (0.12 sec)
Deletion is irreversible and removes all tables, views, routines, triggers, and events in exampledb.
- Verify the database no longer exists.
mysql> SHOW DATABASES LIKE 'exampledb'; Empty set (0.00 sec)
An empty result confirms the schema name is gone from the server catalog.
- Exit the client.
mysql> EXIT; Bye
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
