> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-postgresql-tls-support.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 将 Amazon Aurora MySQL 设置为 ClickPipes 源的分步指南

# Aurora MySQL 源设置指南

export const Image = ({img, alt, size = "lg"}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} />
      </Frame>
    </div>;
};

本分步指南介绍如何配置 Amazon Aurora MySQL，以便通过 [MySQL ClickPipe](/zh/integrations/clickpipes/mysql/index) 将数据复制到 ClickHouse Cloud。有关 MySQL CDC (变更数据捕获)  的常见问题，请参阅 [MySQL 常见问题页面](/zh/integrations/clickpipes/mysql/faq)。

<div id="enable-binlog-retention-aurora">
  ## 启用二进制日志保留
</div>

二进制日志是一组日志文件，其中记录了对 MySQL 服务器实例所做的数据修改；而复制功能需要这些二进制日志文件。要在 Aurora MySQL 中配置二进制日志保留，您必须先[启用二进制日志记录](#enable-binlog-logging)，然后[增加 binlog 保留时间间隔](#binlog-retention-interval)。

<Steps>
  <Step title="通过自动备份启用二进制日志记录" id="enable-binlog-logging">
    自动备份功能决定 MySQL 是否启用二进制日志记录。您可以在 RDS 控制台中依次进入 **Modify** > **Additional configuration** > **Backup**，然后选中 **Enable automated backups** 复选框 (如果尚未选中) ，为实例配置自动备份。

    <Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/w-Unfx0B83cK7_6Z/images/integrations/data-ingestion/clickpipes/mysql/source/rds/rds-backups.webp?fit=max&auto=format&n=w-Unfx0B83cK7_6Z&q=85&s=7236ad6a5564702878d31e2f32154a6c" alt="在 Aurora 中启用自动备份" size="lg" border width="3230" height="530" data-path="images/integrations/data-ingestion/clickpipes/mysql/source/rds/rds-backups.webp" />

    我们建议根据复制用例，将 **Backup retention period** 设置为合理且较长的值。
  </Step>

  <Step title="增加 binlog 保留时间间隔" id="binlog-retention-interval">
    <Warning>
      如果 ClickPipes 尝试恢复复制，但由于配置的 binlog 保留值，所需的 binlog 文件已被清除，则 ClickPipe 会进入错误状态，并且需要重新同步。
    </Warning>

    默认情况下，Aurora MySQL 会尽快清除 binlog (即 *延迟清除*) 。我们建议将 binlog 保留时间增加到至少 **72 小时**，以确保在故障情况下，复制所需的 binlog 文件仍然可用。要设置 binlog 保留时间 ([`binlog retention hours`](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/mysql-stored-proc-configuring.html#mysql_rds_set_configuration-usage-notes.binlog-retention-hours)) ，请使用 [`mysql.rds_set_configuration`](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/mysql-stored-proc-configuring.html#mysql_rds_set_configuration) 过程：

    [//]: # "注意：大多数 CDC（变更数据捕获）提供商建议使用 Aurora RDS 的最长保留期（7 天/168 小时）。由于这会影响磁盘使用量，我们保守地建议最少设置为 3 天/72 小时。"

    ```text theme={null}
    mysql=> call mysql.rds_set_configuration('binlog retention hours', 72);
    ```

    如果未设置此配置，或将其间隔设置得过短，可能会导致二进制日志出现间断，从而影响 ClickPipes 恢复复制的能力。
  </Step>
</Steps>

<div id="binlog-settings">
  ## 配置 binlog 设置
</div>

在 RDS 控制台中点击你的 MySQL 实例，然后进入 **Configuration** 选项卡，即可找到参数组。

<Tip>
  如果你使用的是 MySQL 集群，则下面的参数可在 [DB 集群](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_WorkingWithParamGroups.CreatingCluster.html) 参数组中找到，而不是 DB 实例参数组。
</Tip>

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/w-Unfx0B83cK7_6Z/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/aurora_config.webp?fit=max&auto=format&n=w-Unfx0B83cK7_6Z&q=85&s=6c7c3ee184e5291d3a74af5beb5df0e4" alt="在 Aurora 中查找参数组的位置" size="lg" border width="1524" height="901" data-path="images/integrations/data-ingestion/clickpipes/mysql/parameter_group/aurora_config.webp" />

<br />

点击参数组链接，进入其详情页。你应该会在右上角看到一个 **Edit** 按钮。

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/w-Unfx0B83cK7_6Z/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/edit_button.webp?fit=max&auto=format&n=w-Unfx0B83cK7_6Z&q=85&s=e26a7d57e442f76a85b7c7e8f35abb67" alt="编辑参数组" size="lg" border width="1662" height="292" data-path="images/integrations/data-ingestion/clickpipes/mysql/parameter_group/edit_button.webp" />

<br />

以下参数需要按如下方式设置：

1. 将 `binlog_format` 设为 `ROW`。

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/w-Unfx0B83cK7_6Z/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_format.webp?fit=max&auto=format&n=w-Unfx0B83cK7_6Z&q=85&s=5a295b9004ecf56ba3be2d4a661b4934" alt="将 binlog 格式设为 ROW" size="lg" border width="960" height="232" data-path="images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_format.webp" />

2. 将 `binlog_row_metadata` 设为 `FULL`。

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/w-Unfx0B83cK7_6Z/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_metadata.webp?fit=max&auto=format&n=w-Unfx0B83cK7_6Z&q=85&s=998466c7780b5731d8cdafd2c7e26e4e" alt="binlog 行元数据" size="lg" border width="934" height="234" data-path="images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_metadata.webp" />

3. 将 `binlog_row_image` 设为 `FULL`。

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/w-Unfx0B83cK7_6Z/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_image.webp?fit=max&auto=format&n=w-Unfx0B83cK7_6Z&q=85&s=88ab16be97b12e410aa1ec006c6082b1" alt="binlog 行镜像" size="lg" border width="934" height="234" data-path="images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_image.webp" />

<br />

然后，点击右上角的 **Save Changes**。你可能需要重启实例，更改才能生效——判断方法是：如果你在 Aurora 实例的 **Configuration** 选项卡中看到参数组链接旁显示 `Pending reboot`，就说明需要重启。

<div id="gtid-mode">
  ## 启用 GTID 模式 (推荐)
</div>

<Tip>
  MySQL ClickPipe 也支持在未启用 GTID 模式的情况下进行复制。不过，仍建议启用 GTID 模式，以获得更好的性能并简化故障排查。
</Tip>

[全局事务标识符 (GTID)](https://dev.mysql.com/doc/refman/8.0/en/replication-gtids.html) 是 MySQL 为每个已提交事务分配的唯一 ID。它们可简化 binlog 复制，并使故障排查更加直接。我们**建议**启用 GTID 模式，以便 MySQL ClickPipe 使用基于 GTID 的复制。

Amazon Aurora MySQL v2 (MySQL 5.7) 和 v3 (MySQL 8.0) 以及 Aurora Serverless v2 均支持基于 GTID 的复制。要为 Aurora MySQL 实例启用 GTID 模式，请按以下步骤操作：

1. 在 RDS 控制台中，点击你的 MySQL 实例。
2. 点击 **Configuration** 选项卡。
3. 点击参数组链接。
4. 点击右上角的 **Edit** 按钮。
5. 将 `enforce_gtid_consistency` 设置为 `ON`。
6. 将 `gtid-mode` 设置为 `ON`。
7. 点击右上角的 **Save Changes**。
8. 重启实例，使更改生效。

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/w-Unfx0B83cK7_6Z/images/integrations/data-ingestion/clickpipes/mysql/enable_gtid.webp?fit=max&auto=format&n=w-Unfx0B83cK7_6Z&q=85&s=58a3592e235ebcb20131ce343fb8854e" alt="GTID 已启用" size="lg" border width="1650" height="469" data-path="images/integrations/data-ingestion/clickpipes/mysql/enable_gtid.webp" />

<div id="configure-database-user">
  ## 配置数据库用户
</div>

以管理员用户身份连接到您的 Aurora MySQL 实例，并执行以下命令：

1. 为 ClickPipes 创建一个专用用户：

   ```sql theme={null}
   CREATE USER 'clickpipes_user'@'%' IDENTIFIED BY 'some-password';
   ```

2. 授予 schema 权限。以下示例展示了 `mysql` 数据库的权限。对于您要复制的每个数据库和主机，都需重复执行这些命令：

   ```sql theme={null}
   GRANT SELECT ON `mysql`.* TO 'clickpipes_user'@'host';
   ```

3. 向该用户授予复制权限：

   ```sql theme={null}
   GRANT REPLICATION CLIENT ON *.* TO 'clickpipes_user'@'%';
   GRANT REPLICATION SLAVE ON *.* TO 'clickpipes_user'@'%';
   ```

<div id="iam-authentication">
  ### 使用 IAM 身份验证 (可选)
</div>

您可以不使用密码，改为通过 AWS IAM 的基于角色的访问控制对 ClickPipes 用户进行身份验证。按如下方式创建该用户，然后为其授予与上文所示相同的 schema 和复制特权：

```sql theme={null}
CREATE USER 'clickpipes_iam_user' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';
```

有关设置 ClickPipes 通过这种方式进行身份验证所需的 IAM 角色和策略的完整步骤，请参阅 [AWS IAM DB 身份验证 (RDS/Aurora)](/zh/integrations/clickpipes/postgres/auth)。

<div id="configure-network-access">
  ## 配置网络访问
</div>

<div id="ip-based-access-control">
  ### 基于 IP 的访问控制
</div>

要限制发往 Aurora MySQL 实例的流量，请将[文档中列出的静态 NAT IP 地址](/zh/integrations/clickpipes/home#list-of-static-ips)添加到 Aurora **安全组 (Security Group) **的**入站规则**中。

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/w-Unfx0B83cK7_6Z/images/integrations/data-ingestion/clickpipes/mysql/source/rds/security-group-in-rds-mysql.webp?fit=max&auto=format&n=w-Unfx0B83cK7_6Z&q=85&s=7faf6c4f7a134540a4bfb927436ef8da" alt="在哪里可以找到 Aurora MySQL 的安全组（Security Group）？" size="lg" border width="2850" height="994" data-path="images/integrations/data-ingestion/clickpipes/mysql/source/rds/security-group-in-rds-mysql.webp" />

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/vgIzai2BO-JprHxt/images/integrations/data-ingestion/clickpipes/postgres/source/rds/edit_inbound_rules.webp?fit=max&auto=format&n=vgIzai2BO-JprHxt&q=85&s=e70eeb0cae6c69c9cfd9a34bfc371c48" alt="编辑上述安全组（Security Group）的入站规则" size="lg" border width="1800" height="935" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/rds/edit_inbound_rules.webp" />

<div id="private-access-via-aws-privatelink">
  ### 通过 AWS PrivateLink 进行私有访问
</div>

如需通过私有网络连接到您的 Aurora MySQL 实例，可使用 AWS PrivateLink。请按照 [ClickPipes 的 AWS PrivateLink 设置指南](/zh/resources/support-center/knowledge-base/cloud-services/aws-privatelink-setup-for-clickpipes) 配置连接。

<div id="whats-next">
  ## 接下来做什么？
</div>

现在，您的Amazon Aurora MySQL 实例已配置好 binlog 复制，并已安全连接到 ClickHouse Cloud，您可以[创建您的第一个 MySQL ClickPipe](/zh/integrations/clickpipes/mysql/index#create-your-clickpipe)。如需了解 MySQL CDC (变更数据捕获)  的常见问题，请参阅 [MySQL 常见问题页面](/zh/integrations/clickpipes/mysql/faq)。
