对于 MySQL 模式的租户,可以通过查询 information_schema.databases 来获取该租户下的数据库名称。对于 Oracle 模式的租户,则需要查询 dba_users 或者 all_users 视图来获取相关信息。这里我们假设您主要关心 MySQL 模式的租户。
对于 MySQL 模式的租户:
SELECT tenant_name, database_name
FROM (
SELECT tenant_id, tenant_name FROM oceanbase.gv$tenant WHERE compatibility_mode = 'MySQL'
) AS tenants
JOIN information_schema.schemata ON tenants.tenant_id = DATABASE_ID();
你好,登入root@sys
SELECT
t.tenant_id,
t.tenant_name,
COUNT(d.database_name) AS database_count,
GROUP_CONCAT(d.database_name) AS database_names
FROM
oceanbase.DBA_OB_TENANTS t
LEFT JOIN
oceanbase.CDB_OB_DATABASES d
ON
t.tenant_id = d.tenant_id
GROUP BY
t.tenant_id, t.tenant_name;
你好,登入root@sys
SELECT
t.tenant_id,
t.tenant_name,
COUNT(d.database_name) AS database_count,
GROUP_CONCAT(d.database_name) AS database_names
FROM
oceanbase.DBA_OB_TENANTS t
LEFT JOIN
oceanbase.CDB_OB_DATABASES d
ON
t.tenant_id = d.tenant_id
GROUP BY
t.tenant_id, t.tenant_name;