Description
The CREATE TENANT statement is used to create a user tenant. OceanBase AI Database only supports creating user tenants. The system tenant is automatically created when the cluster is created. A Meta tenant is an internally managed tenant of OceanBase AI Database. A corresponding Meta tenant is created for each user tenant, and their lifecycles are aligned.
By default, a tenant created by using the CREATE TENANT statement has the PRIMARY role.
Limitations and considerations
- When you [create a tenant], you need to allocate a resource pool to the tenant. Therefore, you must plan your resources in advance and create the required resource pools. For more information about how to create a resource pool, see [Create a tenant].
Privilege requirements
Only the root user of the sys tenant (root@sys) can create a tenant. Other tenants do not support creating tenants.
Syntax
The syntax for creating a tenant is as follows:
CREATE TENANT [IF NOT EXISTS] tenant_name [tenant_option_list] [set_sys_var];
tenant_option_list:
tenant_option [, tenant_option...]
tenant_option:
LOCALITY [=] 'locality_description'
| PRIMARY_ZONE [=] primary_zone_name
| RESOURCE_POOL_LIST [=] (pool_name [, pool_name...])
| ENABLE_ARBITRATION_SERVICE [=] {True | False}
| {CHARACTER SET | CHARSET} [=] charset_name
| COLLATE [=] collation_name
| COMMENT [=] 'string'
set_sys_var:
{SET | SET VARIABLES | VARIABLES} var_name {TO | =} var_value [,var_name {TO | =} var_value...]
Parameters
Parameter |
Description |
|---|---|
| tenant_name | Specifies the tenant name. It must be up to 63 bytes in length, contain only uppercase and lowercase English letters, numbers, and underscores, and must start with a letter or underscore. It cannot be a keyword of OceanBase AI Database. |
| IF NOT EXISTS | If the tenant name to be created already exists and you did not specify IF NOT EXISTS, an error will be reported. |
| LOCALITY | Describes the distribution of replicas across zones. The current version supports the following replica types: Full-featured replica: The name is FULL, abbreviated as F. For more information about full-featured replicas, see Full-featured replicas. Example: LOCALITY = 'F@z1,F@z2,F@z3' |
| PRIMARY_ZONE | Specifies the primary zone where the tenant is located. The following values are supported:
If no primary zone is specified when creating a tenant, the default value is RANDOM. |
| RESOURCE_POOL_LIST | Specify the list of resource pools allocated to the tenant. This parameter is required when creating a tenant. If multiple resource pools are specified, the number of UNIT_NUM must be the same for all of them.
NoticeFor multiple resource pools of the same tenant, their corresponding |
| ENABLE_ARBITRATION_SERVICE | No action is required at this time. |
| CHARACTER SET \ | CHARSET | Specify the character set at the tenant level. For more information about character sets, see Character sets. |
| COLLATE | Specify the collation at the tenant level when creating a user tenant. For more information about collations, see Collation. |
| set_sys_var | Specifies the value of a tenant-level system variable. For more information, see var_name. |
| COMMENT | Optional. Enter a comment. |
var_name
Common values of var_name are as follows:
ob_compatibility_mode: Specifies the compatibility mode of the tenant, which can only be specified during creation. Currently, onlymysqlis supported. Ifob_compatibility_modeis not specified, it defaults tomysql.ob_tcp_invited_nodes: Specifies the allowlist for tenant connections, i.e., which client IPs are allowed to connect to the tenant. In the example,%indicates all clients can log in. If the value ofob_tcp_invited_nodesis not specified, the default tenant connection mode allows only local IP addresses to log in to the tenant.lower_case_table_names: controls case sensitivity. It can only be specified when creating a tenant using theCREATE TENANTstatement and cannot be modified via SQL statements after the tenant is created.ob_compatibility_control: Specifies the behavior to be adopted when a conflict with MySQL compatibility behavior occurs. Valid values areMYSQL5.7andMYSQL8.0, indicating whether to follow the behavior of MySQL 5.7 or MySQL 8.0. This variable must be specified when creating a user tenant and can only be set during creation. It cannot be modified after the tenant is created. Ifob_compatibility_controlis not explicitly specified, the default compatibility behavior is to follow MySQL 5.7.read_only: Specifies whether the tenant operates in read-only or read-write mode. If not specified, the default is read-write mode.
Examples
Create a user tenant named test_tenant with the primary zone set to zone1;zone2,zone3, resource pool pool1, character set utf8mb4, and allow connections from all client IPs.
obclient [oceanbase]> CREATE TENANT IF NOT EXISTS test_tenant PRIMARY_ZONE='zone1;zone2,zone3', RESOURCE_POOL_LIST=('pool1'), CHARSET='utf8mb4' SET ob_tcp_invited_nodes TO '%';
References
Create Tenant