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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/information-functions/user.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
