# USER

## Syntax

```sql
USER()
```

## Description

Returns the current MariaDB user name and host name, given when authenticating to MariaDB, as a string in the utf8 [character set](https://mariadb.com/docs/server/reference/data-types/string-data-types/character-sets).

{% hint style="warning" %}
The value of `USER()` may differ from the value of [CURRENT\_USER()](https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/information-functions/current_user), which is the user used to authenticate the current client. [CURRENT\_ROLE()](https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/information-functions/current_role) returns the currently active role.
{% endhint %}

{% tabs %}
{% tab title="Current" %}
`SYSTEM_USER()` is a synonym for `USER()`.
{% endtab %}

{% tab title="< 11.7" %}
`SYSTEM_USER()` and [SESSION\_USER](https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/information-functions/session_user) are synonyms for `USER()`.
{% endtab %}
{% endtabs %}

Statements using the `USER()` function or one of its synonyms are not [safe for statement level replication](https://mariadb.com/docs/server/ha-and-performance/standard-replication/unsafe-statements-for-statement-based-replication).

## Examples

```sql
shell> mysql --user="anonymous"

SELECT USER(),CURRENT_USER();
+---------------------+----------------+
| USER()              | CURRENT_USER() |
+---------------------+----------------+
| anonymous@localhost | @localhost     |
+---------------------+----------------+
```

To select only the IP address, use [SUBSTRING\_INDEX()](https://mariadb.com/docs/server/reference/sql-functions/string-functions/substring_index),

```sql
SELECT SUBSTRING_INDEX(USER(), '@', -1);
+----------------------------------+
| SUBSTRING_INDEX(USER(), '@', -1) |
+----------------------------------+
| 192.168.0.101                    |
+----------------------------------+
```

## See Also

* [CURRENT\_USER()](https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/information-functions/current_user)

<sub>*This page is licensed: GPLv2, originally from*</sub> [<sub>*fill\_help\_tables.sql*</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

{% @marketo/form formId="4316" %}
