A database groups tables and other stored objects. In MySQL or MariaDB, DROP DATABASE permanently deletes the selected database and its objects. You must confirm the server and retain a usable backup first, because recovery after deletion requires restoring that backup.
Current MySQL and MariaDB documentation keeps the syntax at DROP {DATABASE | SCHEMA} [IF EXISTS] db_name. DROP SCHEMA remains a synonym for DROP DATABASE, and the statement drops the database and the objects stored inside it, so confirming the target host and target schema is more important than the deletion syntax itself.
The change is destructive and not something a transaction can roll back, so the practical undo path is a dump, snapshot, or other backup taken before the drop. Current MariaDB packages often use mariadb and mariadb-dump instead of the older mysql and mysqldump compatibility names, and vendor docs also note that database-specific grants are not removed automatically when the schema disappears.
Steps to delete a database in MySQL or MariaDB:
- Back up the database to a file before deleting it.
$ mysqldump --host=db.example.net --user=dbadmin --password --single-transaction --routines --events --databases exampledb > exampledb-before-drop.sql Enter password:
On current MariaDB systems, use mariadb-dump and mariadb where this page shows mysqldump and mysql. --routines and --events keep stored routines and events in the dump, and --databases lets the file recreate the database on restore.
- Check that the backup file exists and is not empty.
$ ls -lh exampledb-before-drop.sql -rw-r--r-- 1 dbadmin dbadmin 6.7K Nov 6 15:45 exampledb-before-drop.sql
- Check the server name and database list from an account that can drop the database.
$ mysql --host=db.example.net --user=dbadmin --password Enter password: mysql> SELECT @@hostname; +------------+ | @@hostname | +------------+ | db-01 | +------------+ 1 row in set (0.00 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | exampledb | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec)
Stop if the host name is not the server you meant or the exact database name is not listed.
- Delete the database.
mysql> DROP DATABASE exampledb; Query OK, 2 rows affected (0.01 sec)
This statement permanently removes exampledb and the objects stored under it. System databases such as mysql, information_schema, performance_schema, and sys must stay in place.
- Confirm that the database is no longer listed.
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
Database-level grants on exampledb stay on the server after the database is gone, so revoke them when they are no longer needed.