> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# CREATE USER

> CREATE USER creates a StarRocks user.

CREATE USER creates a StarRocks user. In StarRocks, a "user\_identity" uniquely identifies a user. From v3.3.3, StarRocks supports setting user properties when creating a user.

***

***

**Tip**

Only users with the `user_admin` role has the privilege to perform this operation.

### Syntax

```SQL theme={null}
CREATE USER [IF NOT EXISTS] <user_identity> 
[auth_option] 
[DEFAULT ROLE <role_name>[, <role_name>, ...]]
[PROPERTIES ("key"="value", ...)]
```

## Parameters

* `user_identity` consists of two parts, "user\_name" and "host", in the format of `username@'userhost'`.  For the "host" part, you can use `%` for fuzzy match. If "host" is not specified, "%" is used by default, meaning that the user can connect to the database from any host.

  The `user_name` part is matched literally: `app_user` does not match `app-user`. Wildcard matching applies only to the `host` part. Native-password usernames are case-sensitive; LDAP users follow the `authentication_ldap_case_insensitive` configuration.

  For the naming conventions of usernames, see [System limits](/documents/4.2/sql-reference/System_limit.md).

* `auth_option` specifies the authentication method. Currently, five authentication methods are supported: the database native password, `mysql_native_password`, `authentication_ldap_simple`, JSON Web Token (JWT) Authentication, and OAuth 2.0 Authentication. The database native password is the same as `mysql_native_password` in logic but slightly differs in syntax. One user identity can use only one authentication method.

  ```SQL theme={null}
  auth_option: {
      IDENTIFIED BY 'auth_string'
      IDENTIFIED WITH mysql_native_password BY 'auth_string'
      IDENTIFIED WITH mysql_native_password AS 'auth_string'
      IDENTIFIED WITH authentication_ldap_simple AS 'auth_string'
      IDENTIFIED WITH authentication_jwt [AS 'auth_properties']
      IDENTIFIED WITH authentication_oauth2 [AS 'auth_properties']
  }
  ```

  | **Authentication method** | **Password for user creation** | **Password for login** |
  | - | - | - |
  | Native password | Plaintext or ciphertext | Plaintext |
  | `mysql_native_password BY` | Plaintext | Plaintext |
  | `mysql_native_password WITH` | Ciphertext | Plaintext |
  | `authentication_ldap_simple` | Plaintext | Plaintext |

  **Note**

  StarRocks encrypts users' passwords before storing them.

  For details of `auth_properties` for JSON Web Token (JWT) Authentication and OAuth 2.0 Authentication, see the corresponding documents:

  * [JSON Web Token Authentication](/documents/4.2/administration/user_privs/authentication/jwt_authentication.md)
  * [OAuth 2.0 Authentication](/documents/4.2/administration/user_privs/authentication/oauth2_authentication.md)

* `DEFAULT ROLE <role_name>[, <role_name>, ...]`: If this parameter is specified, the roles are automatically assigned to the user and activated by default when the user logs in. If not specified, this user does not have any privileges. Make sure that all the roles that are specified already exist.

* `PROPERTIES` sets user properties, including the maximum user connection number (`max_user_connections`), password policy (`PASSWORD_POLICY`), catalog, database or session variables on the user level. User-level session variables take effect as the user logs in. This feature is supported from v3.3.3.

  ```SQL theme={null}
  -- Set the maximum user connection number.
  PROPERTIES ("max_user_connections" = "<Integer>")
  -- Bind an existing password policy to the user.
  PROPERTIES ("PASSWORD_POLICY" = "<policy_name>")
  -- Set the catalog.
  PROPERTIES ("catalog" = "<catalog_name>")
  -- Set the database.
  PROPERTIES ("catalog" = "<catalog_name>", "database" = "<database_name>")
  -- Set session variables.
  PROPERTIES ("session.<variable_name>" = "<value>", ...)
  ```

  **Tip**

  * `PROPERTIES` works on user instead of user identity.
  * `PASSWORD_POLICY` must reference an existing password policy. When set, it takes precedence over the system-level password policy for that user.
  * Global variables and read-only variables cannot be set for a specific user.
  * Variables take effect in the following order: SET\_VAR > Session > User property > Global.
  * You can use [SHOW PROPERTY](/documents/4.2/sql-reference/sql-statements/account-management/SHOW_PROPERTY.md) to view the properties of a specific user.

## Examples

Example 1: Create a user using a plaintext password with no host specified, which is equivalent to `jack@'%'`.

```SQL theme={null}
CREATE USER 'jack' IDENTIFIED BY '123456';
```

Example 2: Create a user using a plaintext password and allow the user to log in from  `'172.10.1.10'`.

```SQL theme={null}
CREATE USER jack@'172.10.1.10' IDENTIFIED WITH mysql_native_password BY '123456';
```

Example 3: Create a user with a ciphertext password and allow the user to log in from  `'172.10.1.10'`.

```SQL theme={null}
CREATE USER jack@'172.10.1.10' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9';
CREATE USER jack@'172.10.1.10' IDENTIFIED WITH mysql_native_password AS '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9';
```

> Note: You can get the encrypted password using the password() function.

Example 4: Create a user who is allowed to log in from a domain name 'example\_domain'.

```SQL theme={null}
CREATE USER 'jack'@['example_domain'] IDENTIFIED BY '123456';
```

Example 5: Create a user that uses LDAP authentication.

```SQL theme={null}
CREATE USER jack@'172.10.1.10' IDENTIFIED WITH authentication_ldap_simple;
```

Example 6: Create a user that uses LDAP authentication and specify the distinguished name (DN) of the user in LDAP.

```SQL theme={null}
CREATE USER jack@'172.10.1.10' IDENTIFIED WITH authentication_ldap_simple AS 'uid=jack,ou=company,dc=example,dc=com';
```

Example 7: Create a user who is allowed to log in from the '192.168' subnet and set `db_admin` and `user_admin` as the default roles for the user.

```SQL theme={null}
CREATE USER 'jack'@'192.168.%' DEFAULT ROLE db_admin, user_admin;
```

Example 8: Create a user and set its maximum user connection number to `600`.

```SQL theme={null}
CREATE USER 'jack'@'192.168.%' PROPERTIES ("max_user_connections" = "600");
```

Example 9: Create a user and set the catalog of the user to `hive_catalog`.

```SQL theme={null}
CREATE USER 'jack'@'192.168.%' PROPERTIES ('catalog' = 'hive_catalog');
```

Example 10: Create a user and set the database of the user to `test_db` in the default catalog.

```SQL theme={null}
CREATE USER 'jack'@'192.168.%' PROPERTIES ('catalog' = 'default_catalog', 'database' = 'test_db');
```

Example 11: Create a user and set the session variable `query_timeout` to `600` for the user.

```SQL theme={null}
CREATE USER 'jack'@'192.168.%' PROPERTIES ('session.query_timeout' = '600');
```

Example 12: Create a user with JSON Web Token Authentication.

```SQL theme={null}
CREATE USER tom IDENTIFIED WITH authentication_jwt AS
'{
  "jwks_url": "http://localhost:38080/realms/master/protocol/jwt/certs",
  "principal_field": "preferred_username",
  "required_issuer": "http://localhost:38080/realms/master",
  "required_audience": "starrocks"
}';
```

Example 13: Create a user and bind an existing password policy.

```SQL theme={null}
CREATE USER 'jack'@'192.168.%' IDENTIFIED BY '123456Ab!' PROPERTIES ('PASSWORD_POLICY' = 'app_password_policy');
```

Example 14: Create a user with OAuth 2.0 Authentication.

```SQL theme={null}
CREATE USER tom IDENTIFIED WITH authentication_oauth2 AS 
'{
  "auth_server_url": "http://localhost:38080/realms/master/protocol/openid-connect/auth",
  "token_server_url": "http://localhost:38080/realms/master/protocol/openid-connect/token",
  "client_id": "12345",
  "client_secret": "LsWyD9vPcM3LHxLZfzJsuoBwWQFBLcoR",
  "redirect_url": "http://localhost:8030/api/oauth2",
  "jwks_url": "http://localhost:38080/realms/master/protocol/openid-connect/certs",
  "principal_field": "preferred_username",
  "required_issuer": "http://localhost:38080/realms/master",
  "required_audience": "12345"
}';
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.