Open In App

MySQL | DATABASE() and CURRENT_USER() Functions

Improve
Improve
Like Article
Like
Save
Share
Report

DATABASE() Function

The DATABASE() Function in MySQL returns the name of the default or current database. The string or name returned by DATABASE() function uses the utf8 character set. If there is no default database,the Database function returns NULL. 
In the older versions than MySQL 4.1.1,The Database function used to return an empty string, if there is no default database. 

Syntax : 
 

SELECT DATABASE();

The DATABASE() function is easy to use and does not accept any parameters. We can easily get the name of default database using the above syntax on MySQL console. 

Example : 
Let us consider the name of the default database is “Employees”. Therefore to know the name of the default database, the database function can be executed in the following way: 
 

Output: 
 

'Employees'

 

CURRENT_USER() Function

The CURRENT_USER() Function in MySQL is used to return the user name and host name for the MySQL account which is used by the server to authenticate the current client. 

As of MySQL 4.1.,the CURRENT_USER() function uses the utf8 character set. 

Syntax: 
 

SELECT CURRENT_USER();

CURRENT_USER() function also does not accepts any parameters. 

Example : 
Let us consider the username of MySQL account used by the server to authenticate the current client is ‘root’ and the hostname is ‘localhost’. Therefore to know the username and hostname for the MySQL account used by the server to authenticate the current client, the CURRENT_USER() function can be executed in the following way: 
 

Output: 
 

'root@localhost'

 


Last Updated : 21 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads