MySQL CURRENT_USER() Function

The MySQL CURRENT_USER() function returns the username and hostname of the MySQL account that the MySQL server uses to authenticate the current client.

CURRENT_USER() Syntax

Here is the syntax of the MySQL CURRENT_USER() function:

CURRENT_USER()

or

CURRENT_USER

Parameters

The MySQL CURRENT_USER() function does not require any parameters.

Return value

The CURRENT_USER() function returns a UTF8 string that is the username and hostname used by the MySQL server to authenticate the current client’s MySQL account.

The CURRENT_USER() function are similar to the USER() function, but their values ​​may be different. The USER() function returns the current username and hostname.

CURRENT_USER() Examples

The following example shows how to use the current user information using the CURRENT_USER() function.

SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| root@%         |
+----------------+

The value of CURRENT_USER() and USER() may be different, as follows:

SELECT CURRENT_USER(), USER();
+----------------+--------------------+
| CURRENT_USER() | USER()             |
+----------------+--------------------+
| root@%         | [email protected] |
+----------------+--------------------+

Here, the CURRENT_USER() function returns the username and hostname of the MySQL account used by the MySQL server to authenticate the current client, and the USER() function returns the username and hostname of the current MySQL account.