If a user temporarily does not need access to OceanBase Database, the administrator can lock the user. A locked user cannot log on to the database. The administrator can also unlock users to reactivate them.
Prerequisites
The operation of locking or unlocking a user is generally performed by the administrator. If a regular user needs to perform the locking or unlocking operation, they must have the global ALTER USER privilege. For information about how to view user privileges, see View user privileges. If the user does not have the global ALTER USER privilege, contact the administrator to obtain the privilege. For information about how to grant privileges to a user, see Modify user privileges.
Procedure
Log on to a MySQL tenant of the cluster.
Lock or unlock a user.
The syntax is as follows:
ALTER USER user_name ACCOUNT LOCK | UNLOCK;Here are some examples:
Lock a user
obclient> ALTER USER demo ACCOUNT LOCK; Query OK, 0 rows affected obclient -udemo@demo0_111 -P2881 -h10.10.10.1 -p****** obclient: [Warning] Using a password on the command line interface can be insecure. ERROR 3118 (HY000): User lockedUnlock a user
obclient> ALTER USER demo ACCOUNT UNLOCK; Query OK, 0 rows affected (0.02 sec) obclient> obclient -udemo@demo0_111 -P2881 -h10.10.10.1 -p****** Welcome to the OceanBase. Commands end with ; or \g. Your OceanBase connection id is 3221583856 Server version: OceanBase 4.0.0.0 (r100000172022101218-6ab80a3950710941946c004d805fcfded7a4aa2c) (Built Oct 12 2022 18:43:39) Copyright (c) 2000, 2018, OceanBase Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. obclient>
Query the
is_lockedfield in theDBA_OB_USERSview to verify the locking status of the user as the administrator.Here is an example:
obclient [(none)]> SELECT user_name,is_locked FROM oceanbase.DBA_OB_USERS WHERE user_name='demo'; +-----------+-----------+ | user_name | is_locked | +-----------+-----------+ | demo | NO | +-----------+-----------+ 1 row in setIf the value of the
is_lockedfield isYES, the user is locked. If the value of theis_lockedfield isNO, the user is unlocked.
References
For more information about the ALTER USER statement, see ALTER USER.