MariaDB USER() Function

In MariaDB, 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 USER() Syntax

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

USER()

Parameters

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

Return value

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

MariaDB USER() Examples

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

SELECT USER();

Output:

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

USER() vs CURRENT_USER()

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(),
  USER();

Output:

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

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

Conclusion

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