The CREATE USER statement is used to create a Doris user.
CREATE USER [IF EXISTS] <user_identity> [IDENTIFIED BY <password>] [DEFAULT ROLE <role_name>] [<password_policy>] [<comment>] password_policy: 1. PASSWORD_HISTORY { <n> | DEFAULT } 2. PASSWORD_EXPIRE { DEFAULT | NEVER | INTERVAL <n> { DAY | HOUR | SECOND }} 3. FAILED_LOGIN_ATTEMPTS <n> 4. PASSWORD_LOCK_TIME { UNBOUNDED | <n> { DAY | HOUR | SECOND }}
1. <user_identity>
A user_identity uniquely identifies a user.The syntax is:‘user_name’@‘host’.
user_identityconsists of two parts, user_name and host, where username is the username. Host identifies the host address where the client connects. The host part can use % for fuzzy matching. If no host is specified, it defaults to ‘%’, which means the user can connect to Doris from any host. The host part can also be specified as a domain, the syntax is: ‘user_name’@[‘domain’], even if it is surrounded by square brackets, Doris will think this is a domain and try to resolve its ip address.
1. <password>
Specify the user password.
2. <role_name>
Specify the user role. If a role (ROLE) is specified, the newly created user will be automatically granted the permissions of the role. If not specified, the user has no permissions by default. The specified ROLE must already exist.
3. <password_policy>
password_policyis a clause used to specify policies related to password authentication login. Currently, the following policies are supported:
PASSWORD_HISTORY { <n> | DEFAULT }Whether to allow the current user to use historical passwords when resetting their passwords. For example,
PASSWORD_HISTORY 10means that it is forbidden to use the password set in the past 10 times as a new password. If set toPASSWORD_HISTORY DEFAULT, the value in the global variablepassword_historywill be used.0means do not enable this feature. Default is 0.
PASSWORD_EXPIRE { DEFAULT | NEVER | INTERVAL <n> { DAY | HOUR | SECOND }}Set the expiration time of the current user's password. For example
PASSWORD_EXPIRE INTERVAL 10 DAYmeans the password will expire in 10 days.PASSWORD_EXPIRE NEVERmeans that the password does not expire. If set toPASSWORD_EXPIRE DEFAULT, the value in the global variabledefault_password_lifetimeis used. Defaults to NEVER (or 0), which means it will not expire.
FAILED_LOGIN_ATTEMPTS <n>When the current user logs in, if the user logs in with the wrong password for n times, the account will be locked.For example,
FAILED_LOGIN_ATTEMPTS 3means that if you log in wrongly for 3 times, the account will be locked.
PASSWORD_LOCK_TIME { UNBOUNDED | <n> { DAY | HOUR | SECOND }}When the account is locked, the lock time is set. For example,
PASSWORD_LOCK_TIME 1 DAYmeans that the account will be locked for one day.
4. <comment>
Specify the user comment.
The user executing this SQL command must have at least the following privileges:
| Privilege | Object | Notes |
|---|---|---|
| ADMIN_PRIV | USER or ROLE | This operation can only be performed by users or roles with ADMIN_PRIV permissions |
CREATE USER 'jack';
CREATE USER jack@'172.10.1.10' IDENTIFIED BY '123456';
CREATE USER jack@'172.10.1.10' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9'; The encrypted content can be obtained through PASSWORD(), for example: SELECT PASSWORD('123456');
CREATE USER 'jack'@'192.168.%' DEFAULT ROLE 'example_role';
CREATE USER 'jack'@['example_domain'] IDENTIFIED BY '12345';
CREATE USER 'jack'@'%' IDENTIFIED BY '12345' DEFAULT ROLE 'my_role';
CREATE USER 'jack' IDENTIFIED BY '12345' PASSWORD_EXPIRE INTERVAL 10 DAY FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 1 DAY;
CREATE USER 'jack' IDENTIFIED BY '12345' PASSWORD_HISTORY 8;
CREATE USER 'jack' COMMENT "this is my first user";