Connect to an OceanBase tenant by using OBClient

2024-04-19 08:42:49  Updated

This topic describes how to connect to an Oracle tenant of OceanBase Database by using OceanBase Client (OBClient).

Prerequisites

  • The OBClient application is downloaded and installed. If OBClient is not downloaded, download the required version from OceanBase Download Center.

  • The client is in the allowlist of the tenant. For more information about how to query and configure a tenant allowlist, see View and set a tenant allowlist.

Procedure

  1. Open a command-line terminal.

  2. Connect to OceanBase Database.

    • To connect to OceanBase Database by using an ODP, run the following command:

      obclient -h10.10.10.1 -uusername@obtenant#obdemo -P2883 -p****** -c -A oceanbase
      

      or

      obclient -h10.10.10.1 -uobdemo:obtenant:username -P2883 -p****** -c -A oceanbase
      

      where

      • -h specifies the IP address for connecting to OceanBase Database, which is usually the IP address of an ODP.

      • -u specifies the tenant account. The following account formats are supported: username@tenant name#cluster name, cluster name:tenant name:username, cluster name-tenant name-username, and cluster name.tenant name.username. The default username of the administrator of an Oracle tenant is SYS.

        Note

        • When connecting to an OceanBase cluster using ODP, you can obtain the cluster name in the following way:
          First, connect directly to OceanBase Database. Then, use the SHOW PARAMETERS LIKE 'cluster'; command to retrieve the name of the cluster. This command will return the name of the OceanBase cluster corresponding to the value of VALUE.
        • If ODP works for multiple clusters, you must specify the cluster name when connecting to it. If ODP works for only one cluster, you do not need to specify the cluster name when connecting to it.

      • -P specifies the port for connecting to OceanBase Database, which is also the listening port of the ODP. The default value is 2883, which can be customized when ODP is deployed.

      • -c specifies that comments must not be ignored in the runtime environment of OBClient.

        Note

        Hint is a special comment that is not affected by the -c option.

      • -A specifies not to automatically retrieve the statistical information when connecting to OceanBase Database.

      • oceanbase specifies the name of the database to be accessed. You can change it to a business database name.

      Here is an example:

      obclient -h10.10.10.1 -u*****@obtenant#obdemo -P2883 -p****** -c -A oceanbase
      

      or

      obclient -h10.10.10.1 -uobdemo:obtenant:***** -P2883 -p****** -c -A oceanbase
      
    • To directly connect to OceanBase Database, run the following command:

      obclient -h10.10.10.1 -uusername@obtenant -P2881 -p****** -c -A oceanbase
      

      where

      • -h specifies the IP address for connecting to OceanBase Database, which is the IP address of an OBServer node.

      • -u specifies the tenant account in the username@tenant name format. The default username of the administrator of an Oracle tenant is sys.

        Notice

        When you directly connect to OceanBase Database, enter the username and tenant name in the format of username@tenant name for the connection parameter -u and do not specify the cluster name. Including the cluster name in -u will cause a connection error.

      • -P specifies the port for connecting to OceanBase Database. The default value is 2881, which can be customized when OceanBase Database is deployed.

      • -p specifies the account password. For security reasons, you do not need to specify this option. In that case, you will be prompted to enter a password later. The password is invisible.

      • -c specifies that comments must not be ignored in the runtime environment of OBClient.

        Note

        Hint is a special comment that is not affected by the -c option.

      • -A specifies not to automatically retrieve the statistical information when connecting to OceanBase Database.

      • oceanbase specifies the name of the database to be accessed. You can change it to a business database name.

      • When you use the direct connection method, make sure that the tenant resources are distributed on the OBServer node you specified. Otherwise, you cannot connect to the tenant by using this OBServer node.

      Here is an example:

      obclient -h10.10.10.1 -u******@obtenant -P2881 -p****** -c -A oceanbase
      
  3. After the connection is established, the following command-line prompt is displayed by default:

    obclient>
    
  4. To exit the OBClient command line, enter exit and press Enter, or press the shortcut key Ctrl + D.

Connection example

The following example shows how to connect to an Oracle tenant of OceanBase Database by using OBClient.

$obclient -h10.10.10.1 -u******@t_oracle0_91#obdoc -P2883 -p****** -c -A sys
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221686103
Server version: OceanBase 4.0.0.0 (r100000302022111120-7cef93737c5cd03331b5f29130c6e80ac950d33b) (Built Nov 11 2022 20:38:33)

Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

obclient> SELECT SYSDATE FROM dual;
+-----------+
| SYSDATE   |
+-----------+
| 28-SEP-22 |
+-----------+
1 row in set

obclient> exit
Bye

References

For information about how to connect to a MySQL tenant of OceanBase Database by using OBClient, see Connect to an OceanBase tenant by using OBClient.

Contact Us