In this article, we will introduce to you the difference between the DATABASE() and CURRENT_USER() functions in MySQL. We hope it will be helpful to friends in need!
DATABASE() function
The DATABASE() function in MySQL returns the name of the default or current database. The string or name returned by the DATABASE() function uses the utf8 character set. If there is no default database, the Database function returns NULL.
In versions older than MySQL 4.1.1, database functions were used to return an empty string if there was no default database.
Syntax:
SELECT DATABASE();
DATABASE() function is easy to use and does not accept any parameters. We can easily get the name of the default database using the above syntax on the MySQL console.
Example:
Let us consider that the name of the default database is "Employees". So, to know the name of the default database, you can execute the database function by:
Output:
'Employees'
CURRENT_USER() function
The CURRENT_USER() function in MySQL is used to return the username and hostname of the MySQL account used by the server to authenticate the current client.
From MySQL 4.1. Initially, the CURRENT_USER() function uses the utf8 character set.
Syntax:
SELECT CURRENT_USER();
The CURRENT_USER() function also does not accept any parameters.
Example:
Let us consider that the username used by the server to authenticate the current client's MySQL account is "root" and the hostname is "localhost". So, to know the username and hostname that the server uses to authenticate the current client's MySQL account, you can execute the CURRENT_USER() function in the following way:
Output:
'root@localhost'
This article is an introduction to the DATABASE() and CURRENT_USER() functions in MySQL. More mysql tutorials are recommended: "mysql tutorial"
The above is the detailed content of Detailed examples of DATABASE() and CURRENT_USER() functions in MySQL. For more information, please follow other related articles on the PHP Chinese website!