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

> 将 Amazon RDS MySQL 配置为 ClickPipes 源的分步指南

# RDS MySQL 源设置指南

export const IAMAuthentication = ({engine, service, children}) => {
  const services = {
    aurora: {
      name: 'Aurora',
      resource: 'cluster',
      id: 'cluster-xxxxxxxxxxxxxx'
    },
    rds: {
      name: 'RDS',
      resource: 'instance',
      id: 'db-xxxxxxxxxxxxxx'
    }
  };
  const createUserStatements = {
    postgres: `CREATE USER clickpipes_iam_user;
GRANT rds_iam TO clickpipes_iam_user;`,
    mysql: `CREATE USER 'clickpipes_iam_user' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';`
  };
  const svc = services[String(service).toLowerCase()];
  const createUserSql = createUserStatements[String(engine).toLowerCase()];
  if (!svc) throw new Error(`Unsupported IAM authentication service: ${service}`);
  if (!createUserSql) throw new Error(`Unsupported IAM authentication engine: ${engine}`);
  return <>
      <p>
        Instead of a password, you can authenticate the ClickPipes user with an AWS IAM role. This lets ClickPipes connect to your Amazon {svc.name} {svc.resource} without storing database credentials.
      </p>

      <h4 id="enable-iam-authentication">Enable IAM authentication</h4>

      <ol>
        <li>Log in to your AWS account and go to the {svc.name} {svc.resource} you want to configure.</li>
        <li>Click <strong>Modify</strong>.</li>
        <li>Scroll to the <strong>Database authentication</strong> section.</li>
        <li>Select <strong>Password and IAM database authentication</strong>.</li>
        <li>Click <strong>Continue</strong>.</li>
        <li>Review the changes and select <strong>Apply immediately</strong>.</li>
      </ol>

      <h4 id="create-database-user">Create the ClickPipes user</h4>

      <p>Create the ClickPipes user with IAM authentication enabled, then grant it the same schema and replication privileges shown above:</p>

      <CodeBlock language="sql">{createUserSql}</CodeBlock>

      {children}

      <h4 id="obtaining-the-clickhouse-service-iam-role-arn">Obtain the ClickHouse service IAM role ARN</h4>

      <ol>
        <li>Log in to your ClickHouse Cloud account.</li>
        <li>Select the ClickHouse service you want to connect.</li>
        <li>Select the <strong>Settings</strong> tab.</li>
        <li>Scroll to the <strong>Network security information</strong> section at the bottom of the page.</li>
        <li>Copy the service's <strong>Service role ID (IAM)</strong> value, shown below.</li>
      </ol>

      <Frame>
        <img src="/images/cloud/security/secures3_arn.webp" alt="Service role ID (IAM) value in the Network security information section" />
      </Frame>

      <p>This value is your <code>{'{ClickHouse_IAM_ARN}'}</code> — the role ClickPipes uses to access your {svc.name} {svc.resource}.</p>

      <h4 id="obtaining-the-rds-resource-id">Obtain the resource ID</h4>

      <ol>
        <li>Log in to your AWS account and go to the {svc.name} {svc.resource} you want to configure.</li>
        <li>Select the <strong>Configuration</strong> tab.</li>
        <li>Note the <strong>Resource ID</strong> value — it looks like <code>{svc.id}</code>. This is your <code>{'{RDS_RESOURCE_ID}'}</code>, which you reference in the permissions policy.</li>
      </ol>

      <h4 id="manually-create-iam-role">Create the IAM role</h4>

      <ol>
        <li>Log in to your AWS account with an IAM user that has permission to create and manage IAM roles.</li>
        <li>Open the IAM console.</li>
        <li>
          Create a new IAM role with the following trust and permissions policies.

          <p>Trust policy (replace <code>{'{ClickHouse_IAM_ARN}'}</code> with the IAM role ARN of your ClickHouse instance):</p>

          <CodeBlock language="json">{`{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "{ClickHouse_IAM_ARN}"
      },
      "Action": [
        "sts:AssumeRole",
        "sts:TagSession"
      ]
    }
  ]
}`}</CodeBlock>

          <p>Permissions policy (replace <code>{'{RDS_RESOURCE_ID}'}</code> with the resource ID of your {svc.name} {svc.resource}, <code>{'{RDS_REGION}'}</code> with its region, and <code>{'{AWS_ACCOUNT}'}</code> with your AWS account ID):</p>

          <CodeBlock language="json">{`{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "rds-db:connect"
      ],
      "Resource": [
        "arn:aws:rds-db:{RDS_REGION}:{AWS_ACCOUNT}:dbuser:{RDS_RESOURCE_ID}/clickpipes_iam_user"
      ]
    }
  ]
}`}</CodeBlock>
        </li>
        <li>Once the role is created, copy its ARN. This is your <code>{'{RDS_ACCESS_IAM_ROLE_ARN}'}</code>.</li>
      </ol>

      <p>You can now use this IAM role to authenticate with your {svc.name} {svc.resource} from ClickPipes.</p>
    </>;
};

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 RDS MySQL，使用 [MySQL ClickPipe](/zh/integrations/clickpipes/mysql/index) 将数据复制到 ClickHouse Cloud。有关 MySQL CDC 的常见问题，请参阅 [MySQL 常见问题页面](/zh/integrations/clickpipes/mysql/faq)。

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

二进制日志是一组日志文件，包含对 MySQL 服务器实例所做的数据修改信息，而复制需要这些二进制日志文件。要在 RDS 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-revert-104359-revert-104251-parquet-single/4ZDv2f4M_2GbJ9Bg/images/integrations/data-ingestion/clickpipes/mysql/source/rds/rds-backups.webp?fit=max&auto=format&n=4ZDv2f4M_2GbJ9Bg&q=85&s=20b0b92648d5b02b969ed6dbc85b0e17" alt="在 RDS 中启用自动备份" 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 保留值，所需的 二进制日志 文件已被清除，则 ClickPipe 将进入错误状态，并且需要重新同步。
    </Warning>

    默认情况下，Amazon RDS 会尽快清除 二进制日志 (即 *延迟清除*) 。我们建议将 binlog 保留时间间隔增加到至少 **72 小时**，以确保在发生故障时，复制所需的 二进制日志 文件仍然可用。要设置 二进制日志 的保留时间 ([`binlog retention hours`](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/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/UserGuide/mysql-stored-proc-configuring.html#mysql_rds_set_configuration) 存储过程：

    [//]: # "NOTE 大多数 CDC 提供商建议使用 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 cluster，则下列参数位于 [DB cluster](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_WorkingWithParamGroups.CreatingCluster.html) 参数组中，而不是 DB 实例组中。
</Tip>

<Image img="https://mintcdn.com/private-7c7dfe99-revert-104359-revert-104251-parquet-single/4ZDv2f4M_2GbJ9Bg/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/rds_config.webp?fit=max&auto=format&n=4ZDv2f4M_2GbJ9Bg&q=85&s=85f8ef5f245843997e37aff4af00a67f" alt="在 RDS 中查找参数组的位置" size="lg" border width="708" height="853" data-path="images/integrations/data-ingestion/clickpipes/mysql/parameter_group/rds_config.webp" />

<br />

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

<Image img="https://mintcdn.com/private-7c7dfe99-revert-104359-revert-104251-parquet-single/4ZDv2f4M_2GbJ9Bg/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/edit_button.webp?fit=max&auto=format&n=4ZDv2f4M_2GbJ9Bg&q=85&s=56dd2c8547d89b8f8b484788dcc8afce" alt="编辑参数组" size="lg" border width="1662" height="292" data-path="images/integrations/data-ingestion/clickpipes/mysql/parameter_group/edit_button.webp" />

将以下参数设置为：

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

<Image img="https://mintcdn.com/private-7c7dfe99-revert-104359-revert-104251-parquet-single/4ZDv2f4M_2GbJ9Bg/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_format.webp?fit=max&auto=format&n=4ZDv2f4M_2GbJ9Bg&q=85&s=6e04eaf8367baea37adf3646eed9f2c0" alt="将 binlog format 设为 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-revert-104359-revert-104251-parquet-single/4ZDv2f4M_2GbJ9Bg/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_metadata.webp?fit=max&auto=format&n=4ZDv2f4M_2GbJ9Bg&q=85&s=d386fba4441470da3e99db913b7590f1" alt="将 binlog row metadata 设为 FULL" 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-revert-104359-revert-104251-parquet-single/4ZDv2f4M_2GbJ9Bg/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_image.webp?fit=max&auto=format&n=4ZDv2f4M_2GbJ9Bg&q=85&s=575ce2aa831b497570fa71031e739487" alt="将 binlog row image 设为 FULL" size="lg" border width="934" height="234" data-path="images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_image.webp" />

<br />

然后，点击右上角的 **Save Changes**。你可能需要重启实例，更改才会生效——一个判断方法是：在 RDS 实例的 **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 RDS for MySQL 5.7、8.0 和 8.4 版本支持基于 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-revert-104359-revert-104251-parquet-single/4ZDv2f4M_2GbJ9Bg/images/integrations/data-ingestion/clickpipes/mysql/enable_gtid.webp?fit=max&auto=format&n=4ZDv2f4M_2GbJ9Bg&q=85&s=c5c0a8fbdf44ed38c08bbc6d40b3fef8" alt="GTID 已启用" size="lg" border width="1650" height="469" data-path="images/integrations/data-ingestion/clickpipes/mysql/enable_gtid.webp" />

<br />

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

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

以管理员身份连接到你的 RDS MySQL 实例，并执行以下命令：

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

   ```sql theme={null}
   CREATE USER 'clickpipes_user'@'host' 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>

<IAMAuthentication engine="mysql" service="rds" />

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

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

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

<Image img="https://mintcdn.com/private-7c7dfe99-revert-104359-revert-104251-parquet-single/4ZDv2f4M_2GbJ9Bg/images/integrations/data-ingestion/clickpipes/mysql/source/rds/security-group-in-rds-mysql.webp?fit=max&auto=format&n=4ZDv2f4M_2GbJ9Bg&q=85&s=0ee7eea2b487aec6a24ee9148e6985d6" alt="在 RDS MySQL 中在哪里可以找到安全组？" 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-revert-104359-revert-104251-parquet-single/ICsmB-Qg9LaQwDEB/images/integrations/data-ingestion/clickpipes/postgres/source/rds/edit_inbound_rules.webp?fit=max&auto=format&n=ICsmB-Qg9LaQwDEB&q=85&s=4734c2f05d130a091c679bf50a0685b1" alt="编辑上述安全组的入站规则" 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>

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

<div id="next-steps">
  ## 下一步
</div>

现在，您的亚马逊 RDS MySQL 实例已完成 binlog 复制配置，并已与 ClickHouse Cloud 建立安全连接，您可以[创建第一个 MySQL ClickPipe](/zh/integrations/clickpipes/mysql/index#create-your-clickpipe)。如需了解有关 MySQL CDC 的常见问题，请参见 [MySQL 常见问题页面](/zh/integrations/clickpipes/mysql/faq)。
