OceanBase Client (OBClient) is an interactive batch query tool. You can use it to connect to OceanBase Database.
Prerequisites
The OBClient application is downloaded and installed. You can install the OBClient application by using one of the following methods:
Install the OBClient by using a CLI tool
yum install -y obclientDownload the installation package: visit Software Center, go to the download page of OBClient, and then select the required version to download.
Procedure
Open a command line.
Connect to OceanBase Database.
You can connect to an OceanBase database directly or connect to it by using an OBProxy.
To connect to the MySQL tenant by using an OBProxy, run the following command:
obclient -h10.10.10.1 -u****@obtenant#obdemo -P2883 -ppassword -c -A oceanbaseor
obclient -h10.10.10.1 -uobdemo:obtenant:**** -P2883 -ppassword -c -A oceanbaseNote
-h: specifies the IP address for connecting to OceanBase Database, which is usually the IP address of an OBProxy.
-u: specifies the tenant account. Two account formats are supported:
Username@Tenant name#Cluster nameandCluster name:Tenant name:Username. The default username of the tenant administrator isroot.-P: specifies the port for connecting to OceanBase Database, which is also the listening port of the OBProxy. Default value: 2883, which can be customized.
-p: specifies the account password. For security reasons, you do not need to specify this parameter. In that case, you will be prompted to enter a password later. The password is invisible.
-c: specifies not to ignore comments in the runtime environment.
-A: specifies not to automatically retrieve the statistical information when connecting to the tenant.
oceanbase: the name of the database to be accessed. You can change it to a business database.
Examples:
obclient -h10.10.10.1 -u****@obtenant#obdemo -P2883 -p****** -c -A oceanbaseor
obclient -h10.10.10.1 -uobdemo:obtenant:**** -P2883 -p****** -c -A oceanbaseTo directly connect to the MySQL tenant, run the following command:
obclient -h10.10.10.1 -u****@obtenant -P2881 -ppassword -c -A oceanbaseNote
-h: specifies the IP address for connecting to an OceanBase database, which is usually the IP address of an OBServer.
-u: specifies the tenant account in the
Username@Tenant nameformat. The default username of the tenant administrator isroot.-P: specifies the port for connecting to OceanBase Database. Default value: 2881, which can be customized.
-p: specifies the account password. For security reasons, you do not need to specify this parameter. In that case, you will be prompted to enter a password later. The password is invisible.
-c: specifies not to ignore comments in the runtime environment.
-A: specifies not to automatically retrieve the statistical information when connecting to the tenant.
oceanbase: the name of the database to be accessed. You can change it to a business database.
When you use the direct connection method, make sure that the tenant resources are distributed on the OBServer you specified. Otherwise, you cannot connect to the tenant by using this OBServer.
Example:
obclient -h10.10.10.1 -u******@obtenant -P2881 -p****** -c -A oceanbase
After the connection is established, the following command-line prompt is displayed by default:
obclient>To exit the OBClient command line, enter
exitand press Enter, or press the shortcut key Ctrl + D.
Example
Connect to OceanBase Database by using OBClient
$obclient -h10.10.10.1 -u****@obmysql#obdemo -P2883 -p****** -c -A sys
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 5751
Server version: 5.6.25 OceanBase 4.0.0 (r10100032022041510-a09d3134c10665f03fd56d7f8bdd413b2b771977) (Built Apr 15 2022 02:16:22)
Copyright (c) 2000, 2022, 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() |
+---------------------+
| 2021-06-29 15:31:50 |
+---------------------+
1 row in set
obclient> exit
Bye