> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-detect-table-modification.mintlify.site/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>
  我们还建议阅读[这里](/zh/integrations/clickpipes/mysql/faq)的 MySQL 常见问题页面。该页面正在持续更新。
</Info>

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

二进制日志是一组日志文件，用于记录对 MySQL 服务器实例中数据所做的修改。二进制日志文件是进行复制所必需的。以下两个步骤都必须执行：

<div id="enable-binlog-logging-rds">
  ### 1. 通过自动备份启用二进制日志
</div>

自动备份功能决定是否为 MySQL 启用二进制日志。可在 AWS 控制台中设置：

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

建议根据复制场景，将备份保留策略设置为较长的时长。

<div id="binlog-retention-hours-rds">
  ### 2. Binlog 保留时长 (小时)
</div>

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);
```

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

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

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/Qdrmbc1T54ihl0_n/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/rds_config.webp?fit=max&auto=format&n=Qdrmbc1T54ihl0_n&q=85&s=161752b6bce88b03775804018ae96347" 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-detect-table-modification/Qdrmbc1T54ihl0_n/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/edit_button.webp?fit=max&auto=format&n=Qdrmbc1T54ihl0_n&q=85&s=15192ff470f529e1d8929292b80d2d76" 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-detect-table-modification/Qdrmbc1T54ihl0_n/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_format.webp?fit=max&auto=format&n=Qdrmbc1T54ihl0_n&q=85&s=538ac4d105d9090e01c8c0d820f93cde" 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-detect-table-modification/Qdrmbc1T54ihl0_n/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_metadata.webp?fit=max&auto=format&n=Qdrmbc1T54ihl0_n&q=85&s=2a8bb8ec83b7dcb3700ae4109201bf24" 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-detect-table-modification/Qdrmbc1T54ihl0_n/images/integrations/data-ingestion/clickpipes/mysql/parameter_group/binlog_row_image.webp?fit=max&auto=format&n=Qdrmbc1T54ihl0_n&q=85&s=584f5f33af3a683339880f79aca732aa" 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) 参数组 中，而不是 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 地址](/zh/integrations/clickpipes/home#list-of-static-ips)添加到 RDS 安全组 (Security Group)  的 `Inbound rules` 中。

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/Qdrmbc1T54ihl0_n/images/integrations/data-ingestion/clickpipes/mysql/source/rds/security-group-in-rds-mysql.webp?fit=max&auto=format&n=Qdrmbc1T54ihl0_n&q=85&s=71300997912778c80deba5b411225fd6" 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-detect-table-modification/nH26ELfEvmC8yX3w/images/integrations/data-ingestion/clickpipes/postgres/source/rds/edit_inbound_rules.webp?fit=max&auto=format&n=nH26ELfEvmC8yX3w&q=85&s=fd70b9d17dea4a777163ef8237fd6e5f" 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 配置指南](/zh/resources/support-center/knowledge-base/cloud-services/aws-privatelink-setup-for-clickpipes) 完成连接设置。
