首页  :: 新随笔  :: 管理

OceanBase数据库租户锁定与解锁

Posted on 2023-05-10 16:06  高&玉  阅读(266)  评论(0编辑  收藏  举报

OceanBase数据库支持对租户的锁定。租户锁定后,不影响已连接租户的应用,新应用无法连接租户。

 

使用root用户连接sys租户

[root]# mysql -h192.168.1.71 -P2883 -D oceanbase -uroot@sys -pOceanBase010 -c -A

 

查看租户信息

mysql> select * from dba_ob_tenants;
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+------------------------------+-------------------+--------------------+--------+---------------+--------+
| TENANT_ID | TENANT_NAME | TENANT_TYPE | CREATE_TIME                | MODIFY_TIME                | PRIMARY_ZONE | LOCALITY                     | PREVIOUS_LOCALITY | COMPATIBILITY_MODE | STATUS | IN_RECYCLEBIN | LOCKED |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+------------------------------+-------------------+--------------------+--------+---------------+--------+
|         1 | sys         | SYS         | 2023-04-24 18:33:06.821930 | 2023-05-09 09:28:07.989177 | RANDOM       | FULL{1}@zone1, FULL{1}@zone2 | NULL              | MYSQL              | NORMAL | NO            | NO     |
|      1003 | META$1004   | META        | 2023-04-25 16:54:07.990306 | 2023-05-10 15:29:00.135387 | zone1;zone2  | FULL{1}@zone1, FULL{1}@zone2 | NULL              | MYSQL              | NORMAL | NO            | NO     |
|      1004 | my_tenant   | USER        | 2023-04-25 16:54:07.991849 | 2023-05-10 15:29:00.123178 | zone1;zone2  | FULL{1}@zone1, FULL{1}@zone2 | NULL              | MYSQL              | NORMAL | NO            | NO     |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+------------------------------+-------------------+--------------------+--------+---------------+--------+

 

锁定my_tenant租户

mysql> alter tenant my_tenant lock;
Query OK, 0 rows affected (0.23 sec)

 

查看租户信息,此时my_tenant租户LOCKED值处于“YES”(被锁定状态)

mysql> select TENANT_NAME,LOCKED from dba_ob_tenants where TENANT_NAME='my_tenant';
+-------------+--------+
| TENANT_NAME | LOCKED |
+-------------+--------+
| my_tenant   | YES    |
+-------------+--------+

 

新建连接,连接my_tenant租户,会报错my_tenant被锁定

[root]# mysql -h 192.168.1.71 -P 2883 -uroot@my_tenant -pOceanBase010 -A
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 5260 (HY000): Tenant 'my_tenant' is locked

 

解锁my_tenant租户

mysql> alter tenant my_tenant unlock;
Query OK, 0 rows affected (0.19 sec)

 

查看租户信息,此时my_tenant租户LOCKED值为“NO”

mysql> select TENANT_NAME,LOCKED from dba_ob_tenants where TENANT_NAME='my_tenant';
+-------------+--------+
| TENANT_NAME | LOCKED |
+-------------+--------+
| my_tenant   | NO     |
+-------------+--------+

 

参考:https://www.oceanbase.com/docs/common-oceanbase-database-cn-10000000001697247