MariaDB Drop Database

Summary: in this tutorial, you will learn how to use the MariaDB drop database statement to drop a database from the MariaDB Server.

Introduction to MariaDB drop database statement

The drop database statement deletes a database from the current MariaDB server. This action cannot be undone, therefore, you should be very careful with this statement.

Here is the syntax of the drop database statement:

drop database [if exists] database_name;
Code language: SQL (Structured Query Language) (sql)

In this syntax:

  • First, specify the name of the database that you want to remove after the drop database keywords.
  • Second, use the if exists to conditionally drops the database only if it exists. If you drop a nonexisting database without the if exists option, MariaDB will issue an error. However, if you use the if exists option MariaDB issues a note instead.

To execute the drop database statement successfully, you need to have the drop privilege on the database that you want to delete.

MariaDB drop database statement example

First, show all databases in the current MariaDB server:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| crm                |
| information_schema |
| mysql              |
| nation             |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.00 sec)
Code language: SQL (Structured Query Language) (sql)

Second, drop the crm database by using the drop database statement:

mysql> drop database crm;
Query OK, 0 rows affected (0.02 sec)
Code language: SQL (Structured Query Language) (sql)

In this tutorial, you learned how to use the MariaDB drop database statement to drop a database from the MariaDB Server.

Was this tutorial helpful ?