Purpose
You can use this statement to perform the following operations:
Change the password of an OceanBase Database user.
Lock or unlock a user. A locked user cannot log on to OceanBase Database.
Note
To execute this statement to perform an operation other than changing the password of the current user, you must have the
CREATE USERprivilege.Set the default roles activated for a user upon logon.
Required privileges
To execute the ALTER USER statement, you must have the CREATE USER privilege. For more information about privileges in OceanBase Database, see Privilege types in MySQL mode.
Syntax
Change the password of a user:
ALTER USER 'user_name' IDENTIFIED BY 'password';Lock or unlock a user:
ALTER USER 'user_name' [ACCOUNT LOCK | ACCOUNT UNLOCK];Set the default roles activated for a user upon logon:
ALTER USER user_name DEFAULT ROLE {NONE | ALL | role_name [, role_name ...]};
Parameters
| Parameter | Description |
|---|---|
| user_name | The username. |
| password | The new password. |
| ACCOUNT LOCK | Specifies to lock the user. |
| ACCOUNT UNLOCK | Specifies to unlock the user. |
| NONE | Specifies to deactivate all roles granted to a user. |
| ALL | Specifies to activate all roles granted to a user. |
| role_name | The name of the role to be activated. Separate multiple roles with commas (,). |
Examples
Change the password of user
sqluser01to******.obclient> ALTER USER 'sqluser01' IDENTIFIED BY '******';Lock user
obsqluser01.obclient> ALTER USER 'obsqluser01' ACCOUNT LOCK;Unlock user
obsqluser01.obclient> ALTER USER 'obsqluser01' ACCOUNT UNLOCK;Activate the
role001androle002roles granted to theuser001user by default upon user logon.ALTER USER user001 DEFAULT ROLE role001, role002;