

# 查找 Amazon RDS 数据库实例的连接信息
<a name="CHAP_CommonTasks.Connect.EndpointAndPort"></a>

数据库实例的连接信息包括其端点、端口和有效数据库用户，如主用户。例如，对于 MySQL 数据库实例，假设端点值是 `mydb.123456789012.us-east-1.rds.amazonaws.com`。在这种情况下，端口值是 `3306`，数据库用户是 `admin`。鉴于此信息，您可以在连接字符串中指定以下值：
+ 对于主机或主机名或 DNS 名称，请指定 `mydb.123456789012.us-east-1.rds.amazonaws.com`。
+ 对于端口，请指定 `3306`。
+ 对于用户，请指定 `admin`。

端点对于每个数据库实例都是唯一的，端口和用户的值可能会有所不同。以下列表显示了每个数据库引擎的最常见端口：
+ Db2 – 50000
+ MariaDB – 3306
+ Microsoft SQL Server – 1433
+ MySQL – 3306
+ Oracle – 1521
+ PostgreSQL – 5432

要连接到数据库实例，请使用数据库引擎的任何客户端。例如，您可以使用 mysql 实用程序连接到 MariaDB 或 MySQL 数据库实例。您可以使用 Microsoft SQL Server Management Studio 连接到 SQL Server 数据库实例。您可以使用 Oracle SQL Developer 连接到 Oracle 数据库实例。类似地，可以使用 psql 命令行实用程序连接到 PostgreSQL 数据库实例。

要查找数据库实例的连接信息，请使用 AWS 管理控制台。还可以使用 AWS Command Line Interface（AWS CLI）[describe-db-instances](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instances.html) 命令或 RDS API [DescribeDBInstances](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBInstances.html) 操作。

## 控制台
<a name="CHAP_CommonTasks.Connect.EndpointAndPort.Console"></a>

**在 AWS 管理控制台 中查找数据库实例的连接信息**

1. 登录AWS 管理控制台并通过以下网址打开 Amazon RDS 控制台：[https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)。

1. 在导航窗格中，选择 **数据库** 以显示数据库实例的列表。

1. 选择数据库实例的名称以显示其详细信息。

1. 在**连接和安全性**选项卡上，复制端点。另请注意端口号。您需要端点和端口号才能连接到数据库实例。  
![\[数据库实例的端点和端口\]](http://docs.aws.amazon.com/zh_cn/AmazonRDS/latest/UserGuide/images/endpoint-port.png)

1. 如果需要查找主用户名，请选择 **Configuration (配置)** 选项卡并查看 **Master username (主用户名)** 值。

## AWS CLI
<a name="CHAP_CommonTasks.Connect.EndpointAndPort.CLI"></a>

要使用 AWS CLI 查找数据库实例的连接信息，请调用 [describe-db-instances](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instances.html) 命令。在调用中，查询数据库实例 ID、端点、端口和主用户名。

对于 Linux、macOS 或 Unix：

```
aws rds describe-db-instances \
  --query "*[].[DBInstanceIdentifier,Endpoint.Address,Endpoint.Port,MasterUsername]"
```

对于 Windows：

```
aws rds describe-db-instances ^
  --query "*[].[DBInstanceIdentifier,Endpoint.Address,Endpoint.Port,MasterUsername]"
```

您的输出应类似于以下内容。

```
[
    [
        "mydb",
        "mydb.123456789012.us-east-1.rds.amazonaws.com",
        3306,
        "admin"
    ],
    [
        "myoracledb",
        "myoracledb.123456789012.us-east-1.rds.amazonaws.com",
        1521,
        "dbadmin"
    ],
    [
        "mypostgresqldb",
        "mypostgresqldb.123456789012.us-east-1.rds.amazonaws.com",
        5432,
        "postgresadmin"
    ]
]
```

## RDS API
<a name="CHAP_CommonTasks.Connect.EndpointAndPort.API"></a>

要使用 Amazon RDS API 查找数据库实例的连接信息，请调用 [DescribeDBInstances](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBInstances.html) 操作。在输出中，找到端点地址、端点端口和主用户名的值。