MySQL | DATABASE() and CURRENT_USER() Functions

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() Funtion

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'



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.