Purpose
You can use the CREATE TENANT statement to create a user tenant. OceanBase Database allows you to create only a user tenant. The sys tenant is automatically created when you create a cluster. Meta tenants are used for internal management in OceanBase Database. When you create a user tenant, a corresponding meta tenant is automatically created. The lifecycle of a meta tenant is the same as that of its user tenant.
The default role of a user tenant created by using the CREATE TENANT statement is PRIMARY.
Limitations and considerations
OceanBase Database supports two tenant modes: MySQL and Oracle. You must specify a tenant mode when you create a tenant. You cannot change the tenant mode of a created tenant.
You must allocate resource pools to a tenant when you create it. Therefore, you must plan resources and create resource pools in advance. For more information about how to create a resource pool, see Create a tenant.
Required privileges
You can create a tenant only as the root user of the sys tenant (namely root@sys).
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
| {READ ONLY | READ WRITE}
| COMMENT [=] 'string'
set_sys_var:
{SET | SET VARIABLES | VARIABLES} var_name {TO | =} var_value [,var_name {TO | =} var_value...]
Parameters
| Parameter | Description |
|---|---|
| tenant_name | The name of the tenant. The name must start with a letter or an underscore (_) and cannot exceed 63 characters in length. It can contain letters, digits, and underscores (_), and cannot contain reserved keywords of OceanBase Database. |
| IF NOT EXISTS | If the tenant name already exists and IF NOT EXISTS is not specified, an error will be returned. |
| LOCALITY | The distribution of replicas across zones. For example, F@z1,F@z2,F@z3 indicates that z1, z2, and z3 are full-featured replicas. |
| PRIMARY_ZONE | The primary zone of the tenant. Valid values:
If you do not specify this parameter when you create a tenant, the default value RANDOM is used. |
| RESOURCE_POOL_LIST | The list of resource pools allocated to the tenant. This parameter is required when you create a tenant. If the tenant has multiple resource pools, they must have the same UNIT_NUM value, which indicates the number of resource units.
NoticeThe zones of resource pools allocated to the same tenant must not overlap. |
| ENABLE_ARBITRATION_SERVICE | Specifies whether to enable the arbitration service for the tenant. If you do not specify this parameter, the default value False is used. If the cluster has an arbitration service and you do not enable the arbitration service for a tenant when you create the tenant, you can enable the arbitration service for the tenant later. For more information, see Enable the arbitration service for a tenant. |
| CHARACTER SET | CHARSET | The character set for the tenant. For more information about character sets, see Character sets in the "User tenants (MySQL mode)" chapter and Character sets and collations in the "User tenants (Oracle mode)" chapter. |
| COLLATE | The collation for the tenant. For more information about collations, see Collations in the "User tenants (MySQL mode)" chapter and Character sets and collations in the "User tenants (Oracle mode)" chapter. |
| READ ONLY | READ WRITE | Specifies whether the tenant is a ready-only tenant or a read/write tenant. By default, if you do not specify this parameter, the tenant is a read/write tenant. |
| set_sys_var | The values of tenant-level system variables. The variables are described as follows:
|
| COMMENT | Optional. The comment. |
Examples
Create a MySQL tenant named
test_tenant. Set the primary zone tozone1;zone2,zone3, resource pool topool1, and character set toutf8mb4. Allow all client IP addresses to connect to the tenant.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 '%';Create an Oracle tenant named
tenant1. Set the primary zone tozone1and resource pool topool1. Allow all client IP addresses to connect to the tenant.obclient [oceanbase]> CREATE TENANT tenant1 PRIMARY_ZONE='zone1', RESOURCE_POOL_LIST=('pool1') SET ob_compatibility_mode='oracle', ob_tcp_invited_nodes='%';