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

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

# Aurora 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", background}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  const backgroundColor = background === "white" ? "white" : background === "black" ? "rgb(31 31 28)" : undefined;
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} style={{
    backgroundColor
  }} />
      </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-trino-dialect/ZEyvJTCdFXKmprnu/images/integrations/data-ingestion/clickpipes/mysql/source/rds/rds-backups.webp?fit=max&auto=format&n=ZEyvJTCdFXKmprnu&q=85&s=91cd44fb04281d38ec0b63f6a11a5a6c" 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-trino-dialect/zkBy8QRjLpx6BosZ/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/aurora_config.webp?fit=max&auto=format&n=zkBy8QRjLpx6BosZ&q=85&s=7574946388147a2247734647945519a4" 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-trino-dialect/zkBy8QRjLpx6BosZ/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/edit_button.webp?fit=max&auto=format&n=zkBy8QRjLpx6BosZ&q=85&s=393ccec3725edf92a95cc15df8f00547" 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-trino-dialect/zkBy8QRjLpx6BosZ/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_format.webp?fit=max&auto=format&n=zkBy8QRjLpx6BosZ&q=85&s=c35f70d6504e3ba1886bd74feb009248" 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-trino-dialect/zkBy8QRjLpx6BosZ/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_metadata.webp?fit=max&auto=format&n=zkBy8QRjLpx6BosZ&q=85&s=74a543105efd5e6b42a12fab01d9c15e" 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-trino-dialect/zkBy8QRjLpx6BosZ/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_image.webp?fit=max&auto=format&n=zkBy8QRjLpx6BosZ&q=85&s=5a23b3c7c0e005345a59e49a0376d61b" 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-trino-dialect/zkBy8QRjLpx6BosZ/images/integrations/data-ingestion/clickpipes/mysql/enable_gtid.webp?fit=max&auto=format&n=zkBy8QRjLpx6BosZ&q=85&s=07b38561f7f24e22d7783ebecff3805d" 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>

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

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

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

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

<Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/ZEyvJTCdFXKmprnu/images/integrations/data-ingestion/clickpipes/mysql/source/rds/security-group-in-rds-mysql.webp?fit=max&auto=format&n=ZEyvJTCdFXKmprnu&q=85&s=ac44f969dafd1264c1f0f006477cc3b2" 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-trino-dialect/ZEyvJTCdFXKmprnu/images/integrations/data-ingestion/clickpipes/postgres/source/rds/edit_inbound_rules.webp?fit=max&auto=format&n=ZEyvJTCdFXKmprnu&q=85&s=7e5852a4a8a42c9a438075b917532273" 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)。
