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

> 将 Amazon RDS MariaDB 配置为 ClickPipes 数据源的分步指南

# RDS MariaDB 数据源设置指南

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>;
};

这是一份分步指南，说明如何配置您的 RDS MariaDB 实例，以便通过 MySQL ClickPipe 复制其中的数据。

<br />

<Info>
  我们还建议阅读[这里](/docs/zh/integrations/clickpipes/mysql/faq)的 MySQL 常见问题页面。该页面正在持续更新。
</Info>

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

二进制日志是一组日志文件，其中包含对 MySQL 服务器实例所做的数据修改信息。复制需要二进制日志文件。必须同时执行以下两个步骤：

<Steps>
  <Step title="通过自动备份启用二进制日志记录" id="enable-binlog-logging-rds">
    MySQL 是否启用二进制日志记录由自动备份功能决定。可以在 AWS Console 中进行设置：

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

    建议根据复制用例将备份保留策略设置为足够长的时长。
  </Step>

  <Step title="Binlog 保留时长 (小时)" id="binlog-retention-hours-rds">
    Amazon RDS for MariaDB 设置 binlog 保留时长的方法有所不同。binlog 保留时长是指包含变更的二进制日志文件会保留多久。如果某些变更在 binlog 文件被删除前尚未被读取，复制将无法继续。binlog 保留时长 (小时) 的默认值为 NULL，表示不会保留二进制日志。

    要指定某个 DB 实例上二进制日志的保留小时数，请使用 `mysql.rds_set_configuration` 函数，并将 binlog 保留周期设置得足够长，以确保复制能够进行。建议的最短时长为 `24 hours`。

    ```text theme={null}
    mysql=> call mysql.rds_set_configuration('binlog retention hours', 24);
    ```
  </Step>
</Steps>

<div id="binlog-parameter-group-rds">
  ## 在参数组中配置 binlog 设置
</div>

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

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

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

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

需要按如下方式设置 `binlog_format`、`binlog_row_metadata` 和 `binlog_row_image`：

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

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_format.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=98ccb656415f8e43ebfe03c26f4bf908" 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/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_metadata.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=75008a3321f0b26b2111d8f14d80e3fe" alt="将 Binlog 行元数据设为 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/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_image.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=a5660a6f88829e05eefca1eb7dcea83a" alt="将 Binlog 行镜像设为 FULL" size="lg" border width="934" height="234" data-path="images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_image.webp" />

接下来，点击右上角的 `Save Changes`。这些更改可能需要重启实例后才会生效。如果你在 RDS 实例的 `Configurations` 选项卡中看到参数组链接旁显示 `Pending reboot`，通常就表示需要重启实例。

<br />

<Tip>
  如果你使用的是 MariaDB cluster，则上述参数应位于 [DB Cluster](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_WorkingWithParamGroups.CreatingCluster.html) parameter group 中，而不是 DB instance group 中。
</Tip>

<div id="gtid-mode-rds">
  ## 启用 GTID 模式
</div>

全局事务标识符 (GTID) 是分配给 MySQL/MariaDB 中每个已提交事务的唯一 ID。它可以简化 binlog 复制，并让故障排查更直接。MariaDB 默认启用 GTID 模式，因此无需用户执行任何操作即可使用。

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

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

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

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

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

   ```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="configure-network-access">
  ## 配置网络访问
</div>

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

如果你想限制访问 RDS 实例的流量，请将[文档中列出的静态 NAT IP 地址](/docs/zh/integrations/clickpipes/home#list-of-static-ips)添加到 RDS 安全组 (Security Group) 的 `Inbound rules` 中。

<Image img="https://mintcdn.com/private-7c7dfe99/Rm4A9_kDxZf0ApeE/images/integrations/data-ingestion/clickpipes/mysql/source/rds/security-group-in-rds-mysql.webp?fit=max&auto=format&n=Rm4A9_kDxZf0ApeE&q=85&s=af38397cd478a3e845217f3cc0165a7f" alt="在哪里可以找到 RDS 中的安全组（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/dZZG_-B0EzCG8L4V/images/integrations/data-ingestion/clickpipes/postgres/source/rds/edit_inbound_rules.webp?fit=max&auto=format&n=dZZG_-B0EzCG8L4V&q=85&s=1176aa14815b965b841d70d28b5f0d7c" 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>

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