Description
You can execute the CREATE TENANT statement to create a tenant.
Syntax
CREATE TENANT [IF NOT EXISTS] tenantname
[tenant_characteristic_list] [opt_set_sys_var]
tenant_characteristic_list:
tenant_characteristic [, tenant_characteristic...]
tenant_characteristic:
COMMENT 'string'
|{CHARACTER SET | CHARSET} [=] charsetname
|COLLATE [=] collationname
|REPLICA_NUM [=] num
|ZONE_LIST [=] (zone [, zone...])
|PRIMARY_ZONE [=] zone
|DEFAULT TABLEGROUP [=] {NULL | tablegroup}
|RESOURCE_POOL_LIST [=](poolname [, poolname...])
|LOGONLY_REPLICA_NUM [=] num
|LOCALITY [=] 'locality description'
opt_set_sys_var:
{ SET | SET VARIABLES | VARIABLES } system_var_name = expr [,system_var_name = expr] ...
Parameters
| Parameter | Description |
|---|---|
| tenant_name | The name of the tenant. The name must be a maximum of 64 bytes in length and can contain only letters, digits, and underscores (). The name must start with a letter or an underscore () and cannot be a keyword that is reserved for ApsaraDB for OceanBase. |
| IF NOT EXISTS | If the specified tenant name is used and the IF NOT EXISTS option is added, the system returns an error. |
| RESOURCE_POOL_LIST | The resource pools. This parameter is required when you create a tenant. You can specify only one resource pool. |
| DEFAULT TABLEGROUP | The default table group of the tenant. A NULL value specifies no default table group for the database. If you do not specify this option, the default value is NULL. |
| COMMENT | The comments. |
| CHARACTER SET | CHARSET | The character set for the tenant. |
| COLLATE | The collation. |
| REPLICA_NUM | The number of replicas. |
| ZONE_LIST | The zones. |
| PRIMARY_ZONE | The primary zone. |
| LOGONLY_REPLICA_NUM | The number of log replicas. |
| LOCALITY | The distribution of replicas across zones. For example, the F@z1,F@z2,F@z3,R@z4 value specifies that replicas in the z1, z2, and z3 zones are FULL replicas, and replicas in the z4 zone are READONLY replicas. |
| system_var_name | The system variable of the tenant. The system variable ob_compatibility_mode specifies the compatibility mode of the tenant. You can set the tenant to be compatible with MySQL or Oracle. You can set the value only when you create a tenant. By default, the tenant is compatible with MySQL if you leave ob_compatibility_mode empty. |
Examples
- Create a tenant.
CREATE TENANT IF NOT EXISTS t1 charset='utf8mb4', replica_num=1, zone_list=('zone1'), primary_zone='zone1', resource_pool_list=('pool1');
- Create a tenant that is compatible with Oracle.
CREATE TENANT IF NOT EXISTS t1 zone_list=('zone1'), primary_zone='zone1', resource_pool_list=('pool1') SET ob_compatibility_mode='oracle';
Notes
Before you execute the CREATE TENANT statement to create a tenant, connect your root user to the root tenant root@ROOT.