In MariaDB, USER() is a built-in function that returns the current MariaDB user name and host name, given when authenticating to MariaDB.
Syntax
The syntax goes like this:
USER()
No arguments are required or accepted.
Example
Here’s an example to demonstrate:
SELECT USER();
Result:
+------------------+ | USER() | +------------------+ | barney@localhost | +------------------+
USER() vs CURRENT_USER()
The USER() function doesn’t always return the same result as the CURRENT_USER() function.
For example, if we connect using anonymous:
mariadb --user="anonymous"
Then run USER() and CURRENT_USER():
SELECT
USER(),
CURRENT_USER;
Result:
+---------------------+--------------+ | USER() | CURRENT_USER | +---------------------+--------------+ | anonymous@localhost | @localhost | +---------------------+--------------+
No Arguments are Accepted
Passing any arguments to USER() results in an error:
SELECT USER(123);
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 '123)' at line 1
Statements using the USER() function or one of its synonyms (SYSTEM_USER() and SESSION_USER()) are not safe for statement level replication.