Purpose
You can use this statement to create a tenant.
Note
To execute this statement, you must log on to the
systenant as the root user.
Syntax
CREATE TENANT [IF NOT EXISTS] tenant_name
[tenant_characteristic_list] [opt_set_sys_var];
tenant_characteristic_list:
tenant_characteristic [, tenant_characteristic...]
tenant_characteristic:
COMMENT 'string'
| {CHARACTER SET | CHARSET} [=] charsetname
| COLLATE [=] collationname
| ZONE_LIST [=] (zone [, zone...])
| PRIMARY_ZONE [=] zone
| DEFAULT TABLEGROUP [=] {NULL | tablegroup}
| RESOURCE_POOL_LIST [=](poolname [, poolname...])
| 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 cannot exceed 128 characters in length. It must contain only uppercase and lowercase letters, digits, and underscores (_). The name must start with a letter or an underscore (_) and must not contain reserved keywords of OceanBase Database. |
| IF NOT EXISTS | If the tenant name already exists and IF NOT EXISTS is not specified, an error is returned. |
| RESOURCE_POOL_LIST | The list of resource pools. This parameter is required when you create a tenant. |
| DEFAULT TABLEGROUP | The default table group of the tenant. When you set it to NULL, the system disables the default table group. If this parameter is not specified, the default value is NULL. |
| COMMENT | The comment. |
| CHARACTER SET | CHARSET | The character set of the tenant. |
| COLLATE | The collation. |
| ZONE_LIST | The list of zones to be modified. Note: When you create a tenant, the list of zones must be a subset of all zones in the resource pools of the tenant. |
| PRIMARY_ZONE | The primary zone. |
| LOCALITY | The distribution of replicas across zones. For example, F@z1,F@z2,F@z3,R@z4 indicates that z1, z2, and z3 are full-featured replicas, and z4 is a read-only replica. |
| system_var_name | The system variables of the tenant. ob_compatibility_mode specifies the compatibility mode of the tenant. Valid values: MySQL and Oracle. You can specify the compatibility mode only when you create the tenant. If you do not specify this parameter, the compatibility mode is MySQL by default. |
Examples
Create a MySQL tenant with three replicas.
obclient> CREATE TENANT IF NOT EXISTS test_tenant CHARSET='utf8mb4', ZONE_LIST=('zone1','zone2','zone3'), PRIMARY_ZONE='zone1;zone2,zone3', RESOURCE_POOL_LIST=('pool1');Create a tenant in Oracle mode.
obclient> CREATE TENANT IF NOT EXISTS tenant1 ZONE_LIST=('zone1'), PRIMARY_ZONE='zone1', RESOURCE_POOL_LIST=('pool1') SET ob_compatibility_mode='oracle';