In MariaDB, CURRENT_USER()
is a built-in function that returns the user name and host name combination for the MariaDB account that the server used to authenticate the current client.
Syntax
The function can be called with or without the parentheses:
CURRENT_USER
CURRENT_USER()
No arguments are required or accepted.
Example
Here’s an example to demonstrate:
SELECT CURRENT_USER();
Result:
+------------------+ | CURRENT_USER() | +------------------+ | barney@localhost | +------------------+
Without Parentheses
As mentioned, the CURRENT_USER()
function can be called with or without parentheses.
Here’s an example without parentheses:
SELECT CURRENT_USER;
Result:
+------------------+ | CURRENT_USER | +------------------+ | barney@localhost | +------------------+
Same result.
Anonymous User
Here’s an example of what happens when connected as anonymous.
Connect using anonymous
:
mariadb --user="anonymous"
Run CURRENT_USER
:
SELECT CURRENT_USER;
Result:
+--------------+ | CURRENT_USER | +--------------+ | @localhost | +--------------+
CURRENT_USER()
vs USER()
The CURRENT_USER()
function doesn’t always return the same result as the USER()
function (and its synonyms SYSTEM_USER()
and SESSION_USER()
).
Example:
SELECT
CURRENT_USER,
USER(),
SYSTEM_USER(),
SESSION_USER();
Result:
+--------------+---------------------+---------------------+---------------------+ | CURRENT_USER | USER() | SYSTEM_USER() | SESSION_USER() | +--------------+---------------------+---------------------+---------------------+ | @localhost | anonymous@localhost | anonymous@localhost | anonymous@localhost | +--------------+---------------------+---------------------+---------------------+
No Arguments are Accepted
Passing any arguments to CURRENT_USER()
results in an error:
SELECT CURRENT_USER(1);
Result:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1)' at line 1