MariaDB USER(): Return the Client User and Host
Learn what MariaDB USER() returns, how it differs from CURRENT_USER(), and how to inspect the connecting client and host.
On this page
MariaDB’s USER() returns the user name and host name provided by the client when it connects. It is useful for checking the connection identity, but it may differ from the MariaDB account used for privileges. See the official USER() reference.
Syntax
USER()
The function takes no arguments and returns a string in user@host form.
Inspect the client identity
SELECT USER();
The returned value depends on the account and host reported for this connection. To extract only the host portion, use SUBSTRING_INDEX():
SELECT SUBSTRING_INDEX(USER(), '@', -1) AS client_host;
Compare it with CURRENT_USER()
USER() describes the identity supplied by the client. CURRENT_USER() returns the MariaDB account used to authenticate the client and determine its privileges. Authentication plugins or proxy-user mapping can make the values different:
SELECT
USER() AS client_identity,
CURRENT_USER() AS privilege_account;
Use this comparison when troubleshooting which account matched and whose grants apply. USER() is not an application end-user ID: with a connection pool, many application users can share the same database identity. For per-customer authorization, check the application’s authenticated principal and enforce the appropriate row-level conditions.
In current MariaDB versions, SYSTEM_USER() is a synonym for USER(). SESSION_USER() has version-specific behavior; see the SESSION_USER() guide before relying on it across MariaDB versions.
Replication note
MariaDB lists statements using USER() and its synonyms as unsafe for statement-based replication. Review the replication guidance if the function appears in replicated data changes.
Related functions
SYSTEM_USER()is a synonym forUSER().CURRENT_USER()identifies the account used for privilege checks, with special behavior inside stored procedures.SESSION_USER()captures session-start identity in current MariaDB versions.