> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memorylake.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 获取数据库连接

> 通过 ID 或自定义 ID 获取数据库连接

```
GET /openapi/memorylake/api/v3/db-connections/{connectionId}
```

通过 ID 获取数据库连接。如需用创建时设置的 `custom_id` 查找，请把 `by_custom_id` 设为 `true`，并把自定义 ID 作为路径参数传入。响应中永远不包含密码。

> [!NOTE]
>
> **所需权限：** `dbconn:read`

### 路径参数

**connectionId** `string` *required*

数据库连接 ID；当 `by_custom_id` 为 `true` 时为连接的 `custom_id`

### 查询参数

**by\_custom\_id** `boolean` (default: false)

设为 `true` 时按 `custom_id` 而不是 ID 查找连接

```bash By connection ID theme={null}
curl -X GET 'https://app.memorylake.cn/openapi/memorylake/api/v3/db-connections/dbconn-7c1e9a4b2d6f4a8e9b3c5d7f1a2b4c6d' \
  -H 'Authorization: Bearer sk_xxxxxx'
```

```bash By custom ID theme={null}
curl -X GET 'https://app.memorylake.cn/openapi/memorylake/api/v3/db-connections/sales-warehouse?by_custom_id=true' \
  -H 'Authorization: Bearer sk_xxxxxx'
```

### 响应

**data** `object`

**连接对象**

**id** `string`

数据库连接标识符，请把它当作不透明字符串处理。

**name** `string`

显示名称

**description** `string`

自由格式的描述

**host** `string`

服务器主机名或地址

**port** `integer`

服务器端口

**username** `string`

连接用于认证的用户名

**database** `string`

要读取的数据库名

**custom\_id** `string`

您为这个连接设置的自定义标识符（如果设置过）

**datasource\_count** `integer`

当前通过这个连接读取数据的数据源数量。大于零时不能删除该连接。

**created\_at** `string`

创建时间戳

**updated\_at** `string`

最后更新时间戳

```json Success (200) theme={null}
{
  "success": true,
  "data": {
    "id": "dbconn-7c1e9a4b2d6f4a8e9b3c5d7f1a2b4c6d",
    "name": "Sales warehouse",
    "description": "Read-only replica of the sales database",
    "host": "pg.internal.example.com",
    "port": 5432,
    "username": "analytics_ro",
    "database": "sales",
    "custom_id": "sales-warehouse",
    "datasource_count": 1,
    "created_at": "2026-09-18T07:42:17.139Z",
    "updated_at": "2026-09-18T07:42:17.139Z"
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.