OceanBase
English日本語简体中文
ドキュメントホーム
製品
エコシステム
リリース

データベース

OceanBase CloudOceanBaseデータベース

データベース

OceanBase CloudOceanBaseデータベース
OceanBase CloudOceanBaseデータベース

OceanBaseデータベース

KV - V4.4.2
  • OBKVの概要
  • OBKVのアーキテクチャ
  • OBKV-Table
    • OBKV-Table概要
      • OBKV-Tableの概要
      • OBKV-Tableのコア機能
      • OBKV-Tableデプロイの概要
    • シンプルなKey-Valueストレージのクイックスタート(Java)
    • OBKV-Table Javaクライアントを使ったアプリケーション開発
      • OBKV-Table Java開発ガイド
      • OBKV-Table開発の準備
      • OBKV-Table Javaクライアントを使用してクラスタに接続する
      • OBKV-Table操作例
        • OBKV-Tableへのデータ書き込み
        • OBKV-Tableによるデータのクエリ
        • OBKV-Tableでのデータ更新
        • OBKV-Tableによるデータの削除
      • OBKV-Table Javaクライアントのパラメータ設定
    • OBKV-Table管理
      • OBKV-Table管理の概要
      • OBKV-Tableの高可用性
      • OBKV-Tableのセキュリティ権限
      • OBKV-Tableモニタリングメトリクス
    • OBKV-Tableリファレンス
      • OBKV-Tableのデータモデル
      • OBKV-Tableの操作タイプ
      • OBKV-Tableがサポートするデータ型
      • OBKV-Table全文インデックス
      • OBKV-Tableのグローバルインデックスの使用範囲と例
      • OBKV-Tableの期限切れデータ削除
      • OBKV-Tableのグループコミット
      • OBKV-Tableの弱い整合性読み取りと最寄りデータセンターからの読み取り
      • OBKV-Table関連ビュー
    • OBKV-Table よくある質問
  • OBKV-HBase
    • OBKV-HBaseの概要
    • OBKV-HBaseのコア機能
    • OBKV-HBaseのデプロイ
    • OBKV-HBaseによるアプリケーション開発
      • OBKV-HBase アプリケーション開発の概要
      • OBKV-HBase Javaクライアントを使用したクラスタへの接続
      • HBaseの業務コードをOBKV-HBaseに移行する
      • OBKV-HBase データ操作の例
    • OBKV-HBase 移行ガイド
    • OBKV-HBase管理
      • OBKV-HBase管理の概要
      • OBKV-HBaseの高可用性
      • OBKV-HBaseのセキュリティ権限
      • OBKV-HBaseモニタリングメトリクス
    • OBKV-HBaseクエリの最適化
    • OBKV-HBaseの性能テスト
    • OBKV-HBaseリファレンス
      • OBKV-HBaseデータモデル
      • OBKV-HBaseのデータスキーマ
      • HBaseとの互換インターフェース
      • HBaseと互換性のあるフィルター
      • OBKV-HBaseの自動パーティション分割
      • OBKV-HBaseにおける期限切れデータの削除
      • OBKV-HBaseの弱い整合性読み取りと最寄りデータセンターからの読み取り
      • OBKV-HBase関連ビュー
    • OBKV-HBaseエコシステム統合
      • Flink連携
        • Flinkコネクタを使用してOBKV-HBaseにデータを同期する
        • ネイティブFlinkによるOBKV-HBaseへのアクセス
      • HiveによるOBKV-HBaseへのアクセス
      • SparkによるOBKV-HBaseへのアクセス
  • OBKVリリースノート
    • OBKV Enterprise版

PDF をダウンロード

このページには現在中国語/日本語版がなく、英語版を表示しています。
ドキュメントフィードバック
  1. ドキュメントセンター
  2. OceanBaseデータベース
  3. KV
  4. V4.4.2

Use the OBKV-Table Go client to connect to a cluster

最終更新:2026-09-29 10:40:08

Preparations
Import the obkv-table-client-go dependency
Connect the Go client to an OBServer node
Direct connection mode
ODP mode
.toml file configurations
ClientConfig

This topic describes how to create a Go client instance. For more information about the Go client, visit GitHub wiki.

Note

We recommend that you use the latest version of the Go client. For more information about the latest version of the Go client, visit the Go client repository on GitHub.

Preparations

Before using the OBKV-Table client to connect to the OBKV-Table cluster for data processing, ensure that you have completed the following work:

  • Deployed an OceanBase cluster. For supported deployment plans, deployment methods, and detailed deployment procedures, see Deployment overview.

  • Created a MySQL tenant. For detailed instructions on creating a tenant, refer to Create a tenant.

  • Created a database. For detailed instructions on creating a database, refer to Create a database.

  • Created an OBKV-Table data table. For detailed instructions on creating an OBKV-Table data table, refer to OBKV-Table data models.

Below is a table creation example:

CREATE TABLE IF NOT EXISTS `test` (
    `c1` bigint(20) NOT NULL,
    `c2` bigint(20) NOT NULL,
    PRIMARY KEY (`c1`)
) PARTITION BY KEY(`c1`) PARTITIONS 10;

Import the obkv-table-client-go dependency

Run the following command on the local Go repository to obtain the obkv-table-client-go dependency of the latest version or a specified version:

go get github.com/oceanbase/obkv-table-client-go

Connect the Go client to an OBServer node

You can connect the Go client to an OBServer node in either of the following modes:

  • Direct connection mode: use a config server

  • OceanBase Database Proxy (ODP) mode

You can create a Go client from code or a .toml file on an OBServer node.

Direct connection mode

The syntax is as follows:

func NewClient(
    configUrl string,
    fullUserName string,
    password string,
    sysUserName string,
    sysPassWord string,
    cliConfig *config.ClientConfig) (Client, error) {

Input parameters:

  • configUrl: the URL for obtaining the RootServer list from the config server.
  • fullUserName: the full username, in the format of userName@tenantName#clusterName.
  • passWord: the password of the user specified by userName in fullUserName for accessing OceanBase Database.
  • sysUserName: the username of the user in the sys tenant. Only users in the sys tenant have privileges to access the routing table.
  • sysPassWord: the password of the user in the sys tenant.
  • cliConfig: the client configurations. For more information, see config.ClientConfig.

Response parameters:

  • Client: the client API, which contains insert, get, update, and other methods.
  • error: the error message.

ODP mode

The syntax is as follows:

func NewOdpClient(
    fullUserName string,
    passWord string,
    odpIP string,
    odpRpcPort int,
    database string,
    cliConfig *config.ClientConfig) (Client, error)

Input parameters:

  • fullUserName: the full username, in the format of userName@tenantName#clusterName.
  • passWord: the password of the user specified by userName in fullUserName for accessing OceanBase Database.
  • odpIP: the IP address of ODP.
  • odpRpcPort: the RPC port number of ODP.
  • database: the name of the database to connect to.
  • cliConfig: the client configurations. For more information, see config.ClientConfig.

Response parameters:

  • Client: the client API, which contains insert, get, update, and other methods.
  • error: the error message.

.toml file configurations

The obkv-table-default.toml file is stored in the /configurations directory.

You can choose to specify the parameters in the Direct mode or ODP mode section in the .toml file. For more information about other parameters, see config.ClientConfig.

The syntax is as follows:

func NewClientWithTomlConfig(configFilePath string) (Client, error)

Input parameter:

  • configFilePath: the path of the .toml file.

Response parameters:

  • Client: the client API, which contains insert, get, update, and other methods.
  • error: the error message.

ClientConfig

The syntax is as follows:

type ClientConfig struct {
    ConnPoolMaxConnSize int
    ConnConnectTimeOut  time.Duration
    ConnLoginTimeout    time.Duration
    OperationTimeOut    time.Duration
    LogLevel            log.Level

    TableEntryRefreshLockTimeout     time.Duration
    TableEntryRefreshTryTimes        int
    TableEntryRefreshIntervalBase    time.Duration
    TableEntryRefreshIntervalCeiling time.Duration

    MetadataRefreshInterval    time.Duration
    MetadataRefreshLockTimeout time.Duration

    RsListLocalFileLocation    string
    RsListHttpGetTimeout       time.Duration
    RsListHttpGetRetryTimes    int
    RsListHttpGetRetryInterval time.Duration

    EnableRerouting bool
}

The special parameters are described as follows:

  • ConnPoolMaxConnSize: the number of connections in the connection pool. The default value is 1.
  • ConnConnectTimeOut: the timeout period for a TCP connection. The default value is 1s.
  • ConnLoginTimeout: the timeout period for an authentication operation. The default value is 1s.
  • OperationTimeOut: the timeout period for a single request. The default value is 10s.
  • EnableRerouting: specifies whether to enable rerouting. By default, rerouting is disabled.

次のトピック

OBKVの概要
次へ
このページの内容
Preparations
Import the obkv-table-client-go dependency
Connect the Go client to an OBServer node
Direct connection mode
ODP mode
.toml file configurations
ClientConfig