MariaDB SYSTEM_USER(): Return Value and Examples
Learn what MariaDB SYSTEM_USER() returns, how it compares with USER() and CURRENT_USER(), and how to inspect client and privilege identities.
On this page
MariaDB’s SYSTEM_USER() returns the user name and host name associated with the current connection. It is a synonym for USER(), which reports the identity supplied by the client when it connected. That value can differ from the MariaDB account used to determine privileges, so compare it with CURRENT_USER() when diagnosing account or permission issues.
Syntax
SYSTEM_USER()
The function takes no arguments. Its result is a string in user@host form. The authoritative reference is MariaDB’s SYSTEM_USER() documentation.
Check the connection identity
Run the function in the session you want to inspect:
SELECT SYSTEM_USER();
SYSTEM_USER() and USER() return the same value because they are synonyms. If you need only the host portion, MariaDB documents this pattern:
SELECT SUBSTRING_INDEX(SYSTEM_USER(), '@', -1) AS client_host;
The result depends on how the client connected. It identifies the connection context; it does not identify an end user inside an application that shares one database connection across many people.
Compare it with CURRENT_USER()
Use both functions when you need to see the client identity and the account MariaDB uses for privileges:
SELECT
SYSTEM_USER() AS client_identity,
CURRENT_USER() AS privilege_account;
The values can differ when authentication or proxy-user mapping selects a different MariaDB account. CURRENT_USER() identifies the account whose privileges apply. Inside a stored procedure, it returns the procedure’s DEFINER, so check the routine’s security context before interpreting the result.
For permission troubleshooting, inspect the account and its grants instead of treating SYSTEM_USER() as an authorization check. In a web application that uses a connection pool, use the application’s authenticated user ID for per-customer access checks; every request may otherwise share the same database connection identity.
Replication note
MariaDB lists statements that use USER() or its synonyms, including SYSTEM_USER(), as unsafe for statement-based replication. CURRENT_USER() is also listed as unsafe. Review MariaDB’s documentation on unsafe statements for statement-based replication before using these functions in replicated data changes.
Related functions
USER()reports the client-supplied user and host;SYSTEM_USER()is its synonym.CURRENT_USER()shows the account used for privilege checks, subject to stored-program security context.SESSION_USER()is another related function; see its page for MariaDB’s compatibility behavior.