---
title: "创建 OceanBase 数据源 | OceanBase 文档中心"
description: 创建 OceanBase 数据源 本文为您介绍 OMS 提供的 OpenAPI：创建 OceanBase 数据源。 功能说明 本接口用于根据用户指定的参数创建 OceanBase 数据源。 接口说明 接口约束 本接口适用于 OMS V2.1.2 及以上版本。 请求路径 POST /api/omsp/v2/endpoi…
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*L03BS6f-o40AAAAAAAAAAAAADiGDAQ/original) 迁移服务 OMSV 3.2.2 企业版

# 创建 OceanBase 数据源

更新时间：2023-06-08 10:49:50

本文为您介绍 OMS 提供的 OpenAPI：创建 OceanBase 数据源。

## 功能说明

本接口用于根据用户指定的参数创建 OceanBase 数据源。

## 接口说明

### 接口约束

本接口适用于 OMS V2.1.2 及以上版本。

### 请求路径

`POST /api/omsp/v2/endpoints/oceanbase`

### 请求参数

**Request Body**

```json
{
  "name": "string",
  "ip": "string",
  "port": "integer[int32]",
  "user": "string",
  "password": "string",
  "cluster": "string",
  "tenant": "string",
  "oceanbaseMode": "string (enum: MYSQL, ORACLE)",
  "desc": "string",
  "ocpName": "string",
  "region": "string"
}

```

| 参数 | 类型 | 必选 | 描述 |
| --- | --- | --- | --- |
| name | string | Y | OceanBase 数据源的名称。 |
| ip | string | Y | OceanBase 数据源的 IP，可以是 OceanBase Proxy 的 IP。 |
| port | integer[int32] | Y | OceanBase 数据源的端口，可以是 OceanBase Proxy 的端口。 |
| user | string | Y | OceanBase 数据源用户，请注意，此处不携带集群和租户信息。 |
| password | string | Y | OceanBase 数据源密码。 |
| cluster | string | Y | OceanBase 数据源所属集群。 |
| tenant | string | Y | OceanBase 数据源所属租户。 |
| oceanbaseMode | string | Y | OceanBase 数据源的模式，取值可以是 MYSQL 或 ORACLE。 |
| desc | string | N | OceanBase 数据源的描述。 |
| ocpName | string | Y | OceanBase 数据源关联的 OCP 的名称。 |
| region | string | Y | OceanBase 数据源的地域信息。 |

### 返回结果

您需要确保返回的 `success` 字段为 `true`，并需要记录 ID 字段。

| 参数 | 类型 | 描述 |
| --- | --- | --- |
| success | boolean | 是否调用成功。 |
| code | string | 状态码。 |
| message | string | 描述信息。 |
| advice | string | 建议。 |
| requestId | string | 请求 ID。 |
| pageNumber | integer[int32] | 当前页数。 |
| pageSize | integer[int32] | 每页条数。 |
| totalCount | integer[int64] | 总记录数。 |
| cost | string | 请求耗时。 |
| data | Object | 创建的 OceanBase 数据源的相关信息，具体包含的信息请参见《data 数据结构》。 |

**data 数据结构**

| 参数 | 类型 | 描述 |
| --- | --- | --- |
| dbType | string | 数据源的类型，取值包括 OB_MYSQL 和 OB_ORACLE。 |
| id | string | 数据源终端标识。 |
| name | string | 数据源终端名称。 |
| ip | string | 数据源终端 IP 地址。 |
| port | integer[int32] | 数据源终端开放端口。 |
| username | string | 数据源终端连接账号。 |
| password | string | 数据源终端连接密码。 后端返回的会是空串，以达到隐藏密码的目的。 |
| desc | string | 数据源终端描述。 |
| gmtCreate | string[date] | 数据源的创建时间。 |
| domainParams | Object | OceanBase 数据库扩展信息。 cluster:String, tenant:String |
| version | string | 数据源的版本。 |
| timezone | string | 数据源的时区。 |
| charset | string | 数据源的字符编码。 |
| nlsLengthSemantics | string | `nls_length_semantics` 属性，如果是创建 OceanBase 数据库 Oracle 模式的数据源，会返回本字段。 |
| operatingSystem | string | 操作系统。对于 OceanBase 数据源，不会返回本字段。 |
| region | string | 地域属性。 |
| ocpName | string | OCP 的名称。 |
| role | string | 数据源的角色。取值包括 MASTER 和 SLAVE。 |
| partnerId | string | 主备库 ID。 |
| tryKeepHb | boolean | 是否允许尝试维持心跳，只有数据源角色是 MASTER 时会返回本字段。 |

**domainParams 数据结构**

| 参数 | 类型 | 描述 |
| --- | --- | --- |
| cluster | string | oceanbase 数据源所属集群。 |
| tenant | string | oceanbase 数据源所属租户。 |

## 示例

### 请求示例

```shell
curl --location --request POST 'http://xxx.xxx.xxx.1:8089/api/omsp/v2/endpoints/oceanbase?ctoken=bigfish_ctoken&pageNumber=1&pageSize=10' \
--header 'Authorization: Basic YWRt=' \
--header 'Content-Type: application/json' \
--data '{
    "name": "OB数据源测试",
    "dbType": "OB_MYSQL",
    "ip": "xxx.xxx.xxx.1",
    "port": 2883,
    "user": "root",
    "password": "password",
    "desc": "mysql -hxxx.xxx.xxx.1 -uroot@tenant#cluster -P2883 -ppassword -Dmysql_210",
    "region": "cn-jiangsu",
    "ocpName": "cn-anhui-212-xxx.xxx.xxx.1",
    "oceanbaseMode":"mysql",
    "cluster": "cluster",
    "tenant": "tenant",
    "domainParams": {
      "tenant": "tenant",
      "cluster": "cluster"
    }
}'

```

### 返回示例

```json
{
  "success": true,
  "code": null,
  "message": null,
  "advice": null,
  "requestId": null,
  "pageNumber": null,
  "pageSize": null,
  "totalCount": null,
  "cost": null,
  "data": {
    "dbType": "OB_MYSQL",
    "id": "id",
    "name": "OB数据源测试",
    "ip": "xxx.xxx.xxx.1",
    "port": 2883,
    "username": "username",
    "password": "password",
    "desc": "mysql -hxxx.xxx.xxx.1 -uusername@tenant#cluster -P2883 -ppassword -Dmysql_210",
    "gmtCreate": null,
    "domainParams": {
      "cluster": "cluster",
      "tenant": "tenant"
    },
    "version": null,
    "timezone": null,
    "charset": null,
    "nlsLengthSemantics": null,
    "operatingSystem": null,
    "region": "cn-jiangsu",
    "ocpName": "cn-anhui-212-xxx.xxx.xxx.1",
    "role": null,
    "partnerId": null,
    "tryKeepHb": null
  }
}

```

 上一篇 下一篇 ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
