MariaDB SYSTEM_USER() Explained

In MariaDB, SYSTEM_USER() is a synonym for the USER() function. It returns the current MariaDB user name and host name, given when authenticating to MariaDB.

Syntax

The syntax goes like this:

SYSTEM_USER()

No arguments are required or accepted.

Example

Here’s an example to demonstrate:

SELECT SYSTEM_USER();

Result:

+------------------+
| SYSTEM_USER()    |
+------------------+
| barney@localhost |
+------------------+

SYSTEM_USER() vs CURRENT_USER()

There’s also another function called CURRENT_USER() that does a similar thing. However, it doesn’t always return the same result as SYSTEM_USER().

For example, if we connect using anonymous:

mariadb --user="anonymous"

Then run SYSTEM_USER() and CURRENT_USER():

SELECT 
    SYSTEM_USER(),
    CURRENT_USER;

Result:

+---------------------+--------------+
| SYSTEM_USER()       | CURRENT_USER |
+---------------------+--------------+
| anonymous@localhost | @localhost   |
+---------------------+--------------+

But if we jump back over to our previous session (in the original terminal window), each function returns the same results:

SELECT 
    SYSTEM_USER(),
    CURRENT_USER;

Result:

+------------------+------------------+
| SYSTEM_USER()    | CURRENT_USER     |
+------------------+------------------+
| barney@localhost | barney@localhost |
+------------------+------------------+

No Arguments are Accepted

Passing any arguments to SYSTEM_USER() results in an error:

SELECT SYSTEM_USER(123);

Result:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '123)' at line 1

Statements using the SYSTEM_USER() function (or USER() and SESSION_USER()) are not safe for statement level replication.