MariaDB SESSION_USER() Function

In MariaDB, SESSION_USER() is a built-in function that returns the username and hostname of the current MariaDB account.

SESSION_USER() and SYSTEM_USER() are synonyms for the USER() function.

MariaDB SESSION_USER() Syntax

Here is the syntax of the MariaDB SESSION_USER() function:

SESSION_USER()

Parameters

The MariaDB SESSION_USER() function do not require any parameters.

Return value

The MariaDB SESSION_USER() function returns a UTF8 string that is the username and hostname of the current MySQL account.

MariaDB SESSION_USER() Examples

The following example shows how to use the SESSION_USER() function to get the current user information.

SELECT SESSION_USER();

Output:

+----------------+
| SESSION_USER() |
+----------------+
| root@localhost |
+----------------+

SESSION_USER() vs CURRENT_USER()

SESSION_USER() is different from CURRENT_USER(). CURRENT_USER() returns the username and hostname of the MariaDB account that the MariaDB server uses to authenticate the current client.

SELECT
  CURRENT_USER(),
  SESSION_USER();

Output:

+----------------+----------------+
| CURRENT_USER() | SESSION_USER() |
+----------------+----------------+
| root@%         | root@localhost |
+----------------+----------------+

In this example, CURRENT_USER() returns root@% and SESSION_USER() returns root@localhost.

Conclusion

In MariaDB, SESSION_USER() is a built-in function that returns the username and hostname of the current MariaDB account.