连接 OceanBase 集群
通过 OBClient 连接 OceanBase 集群中租户的前提条件、连接操作和示例。
连接数据库
--语法
obclient -hIP -uusername@obtenant#cluster -P2881 -p****** -c -A
--密码为空示例
obclient -h127.0.0.1 -uroot@sys -P2881 -Doceanbase -A
--密码不为空示例
obclient -h192.168.63.201 -P2881 -uroot@sys -p'ggj0F8Yt0MzZ3mnGy8r8' -Doceanbase -A
参数说明:
- -h:提供 OceanBase 数据库连接 IP,通常是一个 OBServer 节点的 IP 地址。
- -u:提供租户的连接账户,格式:
用户名@租户名#集群名
。MySQL 租户的管理员用户名默认是root
。 - -P:提供 OceanBase 数据库连接端口,默认是 2881,一般为直接连接到对应的 OBServer 节点的端口,即直连方式使用的端口。该端口在部署 OceanBase 数据库时可自定义。
- -p:提供账户密码,为了安全可以不提供,改为在后面提示符下输入,密码文本不可见。
- -c:表示在 MySQL 运行环境中不要忽略注释。
- -A:表示在 MySQL 连接数据库时不自动获取统计信息。
- -D:访问的数据库的名称。
注意:使用 all_in_one 安装包部署后的集群默认集群名为 myoceanbase。可以使用 show parameters like 'cluster'
,查询到其中的 value 为 myoceanbase。
连接成功后,会输出如下:
obclient(root@sys)[oceanbase]>
退出 OBClient 命令行,输入 exit
后回车,或者按快捷键 Ctrl + D 。
连接示例
通过 OBClient 连接 OceanBase 数据库的 sys 租户。
--密码为空
obclient -h127.0.0.1 -uroot@sys -P2881 -Doceanbase -A
--密码不为空
obclient -h192.168.63.201 -P2881 -uroot@sys -p'ggj0F8Yt0MzZ3mnGy8r8' -Doceanbase -A
输出如下:
[root@iZbp1878co9vj4h78qvl8fZ ~]# obclient -h127.0.0.1 -uroot@sys -P2881 -Doceanbase -A
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 3221518949
Server version: OceanBase 4.2.5.4 (r104040052025071121-969b0573b5acaa8702a55910412894a7a33b7382) (Built Jul 11 2025 21:46:10)
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(root@sys)[oceanbase]>