Skip to main content
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

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.
  • 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.
    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:
  • 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.
    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 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@'%'.
Example 2: Create a user using a plaintext password and allow the user to log in from '172.10.1.10'.
Example 3: Create a user with a ciphertext password and allow the user to log in from '172.10.1.10'.
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’.
Example 5: Create a user that uses LDAP authentication.
Example 6: Create a user that uses LDAP authentication and specify the distinguished name (DN) of the user in LDAP.
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.
Example 8: Create a user and set its maximum user connection number to 600.
Example 9: Create a user and set the catalog of the user to hive_catalog.
Example 10: Create a user and set the database of the user to test_db in the default catalog.
Example 11: Create a user and set the session variable query_timeout to 600 for the user.
Example 12: Create a user with JSON Web Token Authentication.
Example 13: Create a user and bind an existing password policy.
Example 14: Create a user with OAuth 2.0 Authentication.