Mysql Database Function

MySQL: DATABASE Function

This tutorial explains how to use the MySQL DATABASE function with syntax and examples.

Description

The MySQL DATABASE function returns the name of the default database.

Syntax

The syntax for the DATABASE function in MySQL is:

DATABASE( )

Parameters or Arguments

There are no parameters or arguments for the DATABASE function in MySQL.

Note

  • The DATABASE function uses the utf8 character set, as of MySQL 4.1.
  • The DATABASE function will return NULL, if there is no default database (Starting in MySQL 4.1.1).
  • The DATABASE function will return an empty string, if there is no default database (Prior to MySQL 4.1.1).

Applies To

The DATABASE function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let's look at some MySQL DATABASE function examples and explore how to use the DATABASE function in MySQL.

For example:

mysql> SELECT DATABASE();
Output: 'quotations'

This DATABASE function example would return the name of the default database. So if our default database was called quotations, this example would return the string 'quotations'.