MariaDB DATABASE() Function

In MariaDB, DATABASE() is a built-in function that returns the current database name as a string.

It is a synonym for SCHEMA() function.

MariaDB DATABASE() Syntax

Here is the syntax of the MariaDB DATABASE() function:

DATABASE()

Parameters

The MariaDB DATABASE() function do not require any parameters.

Return value

The MariaDB DATABASE() function returns a UTF8 string which is the current database name.

If no database has been selected, the DATABASE() function will return NULL.

MariaDB DATABASE() Examples

If you have just connected to the MySQL server and have not selected a database, the DATABASE() function will return NULL.

SELECT DATABASE();

Output:

+------------+
| DATABASE() |
+------------+
| NULL       |
+------------+

Then, you use the USE statement to select testdb as the default database:

USE testdb;

Now, use the DATABASE() function to get the current database:

SELECT DATABASE();

Output:

+------------+
| DATABASE() |
+------------+
| testdb     |
+------------+

Conclusion

In MariaDB, DATABASE() is a built-in function that returns the current database name as a string.