> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/information-functions/user.md).

# USER

## Syntax

```bnf
USER()
```

## Description

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

{% hint style="warning" %}
The value of `USER()` may differ from the value of [CURRENT\_USER()](/docs/server/reference/sql-functions/secondary-functions/information-functions/current_user.md), which is the user used to authenticate the current client. [CURRENT\_ROLE()](/docs/server/reference/sql-functions/secondary-functions/information-functions/current_role.md) 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](/docs/server/reference/sql-functions/secondary-functions/information-functions/session_user.md) are synonyms for `USER()`.
{% endtab %}
{% endtabs %}

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

## 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()](/docs/server/reference/sql-functions/string-functions/substring_index.md),

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

## See Also

* [CURRENT\_USER()](/docs/server/reference/sql-functions/secondary-functions/information-functions/current_user.md)

<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" %}
