The DBLink feature of OceanBase AI Database enables cross-data source access, allowing you to access a remote database from a local one.
Currently, you can create a DBLink between user tenants of OceanBase AI Database. You can also create a DBLink between different user tenants within the same cluster.
Limitations
- Creating a DBLink from a user tenant of OceanBase AI Database to a MySQL database is not supported.
- The DBLink write and reverse link features are not supported.
Prerequisites
The user creating the DBLink must have the CREATE DATABASE LINK privilege. For information about how to grant privileges to users, see Grant privileges directly.
Create a DBLink between OceanBase AI Database instances
To access a remote OceanBase AI Database, you can create a DBLink between user tenants of OceanBase AI Database.
When creating a DBLink to access a specified remote database, you need to specify the name of the DBLink and provide the username, tenant name, database name, password, IP address, port number, and cluster name of the remote database.
The SQL syntax for creating a DBLink between user tenants of OceanBase AI Database is as follows:
CREATE DATABASE LINK [IF NOT EXISTS] dblink_name CONNECT TO user@tenant DATABASE database_name IDENTIFIED BY 'remote_password' HOST 'ip:port' [CLUSTER "cluster_name"];
The parameters are described as follows:
dblink_name: The name of the DBLink to be created.IF NOT EXISTS: This is for compatibility with MySQL database syntax. IfIF NOT EXISTSis specified, no error is reported even if the DBLink to be created already exists. If it is not specified and the DBLink to be created already exists, an error is returned by the system.user: The username for the remote OceanBase AI Database.tenant: The tenant name for the remote OceanBase AI Database.remote_password: The login password for the username in the remote OceanBase AI Database. If the password contains special characters other than digits and letters, such as@#!, you must enclose the password in single or double quotation marks to avoid syntax errors.database_name: The name of the database for the remote user tenant. When reading data through a DBLink, this database is accessed by default. To access another database, you can specify a particular database for a table in the SQL statement.ip: The IP address of the remote OceanBase AI Database. The IP address can be the IP address of the cluster's proxy or the IP address of an OBServer node in the cluster.When the IP address is that of a specified OBServer node, network connectivity must be ensured between the local database and the specified OBServer node.
Note
In addition to IP addresses, OceanBase AI Database also supports domain names. For example,
example.com:port. You can use the appropriate domain name to connect to the remote database based on your actual environment.port: The port number of the remote OceanBase AI Database. You can specify the port number of the cluster's proxy (default is 2883), or the SQL port number of an OBServer node in the cluster (default is 2881).When the port number is the SQL port number of an OBServer node, network connectivity must be ensured between the local database and the specified OBServer node.
cluster_name: The name of the cluster corresponding to the remote OceanBase AI Database. The cluster name is required only when the IP address and port number are those of the cluster's proxy, and the proxy is deployed using the ConfigUrl method. Since the cluster name is case-sensitive, it must be enclosed in double quotation marks.Note
When you deploy a proxy such as ODP for a cluster, there are the following two deployment methods:
- ConfigUrl deployment method: This means that when starting ODP, you query for the Root Server information of the OceanBase AI Database cluster by specifying the
obproxy_config_server_urlparameter in the command. - RsList deployment method: This means that when starting ODP, you specify the Root Server information of the OceanBase AI Database cluster by including the
-rparameter in the command.
- ConfigUrl deployment method: This means that when starting ODP, you query for the Root Server information of the OceanBase AI Database cluster by specifying the
Examples:
Create a DBLink named
ob_dblinkto connect to a remote OceanBase AI Database, where the IP address and port number are those of a specified OBServer node.CREATE DATABASE LINK IF NOT EXISTS ob_dblink CONNECT TO username@mysql DATABASE test IDENTIFIED BY '********' HOST 'xx.xx.xx.xx:2881';Create a DBLink named
ob_dblink_proxyto connect to a remote OceanBase AI Database, where the IP address and port number are those of the cluster's proxy, and the proxy is deployed using the ConfigUrl method.CREATE DATABASE LINK IF NOT EXISTS ob_dblink_proxy CONNECT TO username@mysql DATABASE test IDENTIFIED BY '********' HOST 'xx.xx.xx.xx:2883' CLUSTER "obcluster";Notice
When entering the cluster name, you must add double quotation marks to prevent the letters in the cluster name from being converted to uppercase.
References
For more operations related to DBLink, see the following information: