MariaDB SESSION_USER(): Version Behavior and Examples
Learn how MariaDB SESSION_USER() behaves across versions, how it relates to USER() and CURRENT_USER(), and how to compare session identities.
On this page
MariaDB’s SESSION_USER() reports a user and host associated with the session, but its behavior changed in MariaDB 11.7. Check the server version before relying on it in code. The official SESSION_USER() reference documents both behaviors and the compatibility setting.
Syntax
SESSION_USER()
The function takes no arguments.
Behavior in MariaDB 11.7 and later
In current versions, SESSION_USER() shows the value of CURRENT_USER() from when the session was created. Unlike CURRENT_USER(), that session-start value does not change inside stored routines and views.
SELECT
USER() AS client_identity,
CURRENT_USER() AS privilege_account,
SESSION_USER() AS session_start_account;
USER() reports the identity supplied by the client. CURRENT_USER() reports the account used for privileges in the current execution context; inside a stored procedure, it returns the procedure’s DEFINER. SESSION_USER() preserves the session-start account in those routine and view contexts.
MariaDB versions before 11.7
Before MariaDB 11.7, SESSION_USER() is a synonym for USER(). The older behavior can also be restored with the SESSION_USER_IS_USER setting in old_mode. If a query must behave consistently across versions, review the server version and old_mode rather than assuming the function is an alias.
Replication note
MariaDB lists statements using SESSION_USER() as unsafe for statement-based replication. Review the official replication guidance before using it in replicated data changes.
Related functions
USER()reports the user and host provided by the client when connecting.CURRENT_USER()identifies the account used for privilege checks.SYSTEM_USER()is a synonym forUSER().