Purpose
This statement is mainly used for the following operations:
Modifying the password of an OceanBase Database user.
Locking or unlocking a user. A locked user cannot log in to the database.
Note
Except for modifying the password of the current user, you must have the
CREATE USERprivilege to execute this statement.Setting the default activated role for a user when it logs in.
Modifying the resource options of a user.
Privilege requirements
To execute the ALTER USER statement, the current user must have the CREATE USER privilege. For more information about OceanBase Database privileges, see Privilege types in MySQL mode.
Syntax
Modifying the password of a user:
ALTER USER 'user_name' IDENTIFIED BY 'password';Locking a user:
ALTER USER 'user_name' [ACCOUNT LOCK | ACCOUNT UNLOCK];Setting the default activated role for a user when it logs in:
ALTER USER user_name DEFAULT ROLE {NONE | ALL | role_name [, role_name ...]};Modifying the resource options of a user:
ALTER USER user_name WITH resource_option [resource_option]; resource_option: MAX_CONNECTIONS_PER_HOUR integer | MAX_USER_CONNECTIONS integer
Parameters
| Parameter | Description |
|---|---|
| user_name | The name of the user. |
| password | The new password. |
| ACCOUNT LOCK | Locks the user. |
| ACCOUNT UNLOCK | Unlocks the user. |
| NONE | Disables all roles granted to the user. |
| ALL | Activates all roles granted to the user. |
| role_name | The name of the role. Separate multiple role names with commas (,). |
| resource_option | The resource options of the user. Separate multiple resource options with spaces.
|
Examples
Execute the following command to change the password of the
sqluser01user to******.obclient> ALTER USER 'sqluser01' IDENTIFIED BY '******';Lock the
obsqluser01user.obclient> ALTER USER 'obsqluser01' ACCOUNT LOCK;Unlock the
obsqluser01user.obclient> ALTER USER 'obsqluser01' ACCOUNT UNLOCK;Specify that the
role001androle002roles granted to theuser001user are activated by default when it logs in.ALTER USER user001 DEFAULT ROLE role001, role002;