> ## 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 MySQL を ClickPipes のソースとして設定するためのステップバイステップガイド

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

このガイドでは、[MySQL ClickPipe](/ja/integrations/clickpipes/mysql/index) を使用して、Amazon RDS MySQL から ClickHouse Cloud にデータをレプリケートできるように設定する方法を説明します。MySQL CDC に関するよくある質問については、[MySQL のよくある質問ページ](/ja/integrations/clickpipes/mysql/faq) を参照してください。

<div id="enable-binlog-retention-rds">
  ## バイナリログの保持期間を有効にする
</div>

バイナリログは、MySQL サーバーインスタンスで行われたデータ変更に関する情報を含む一連のログファイルであり、レプリケーションにはバイナリログファイルが必要です。RDS MySQL でバイナリログの保持期間を設定するには、[バイナリログを有効にし](#enable-binlog-logging)、[binlog の保持期間を延長する](#binlog-retention-interval)必要があります。

<div id="enable-binlog-logging">
  ### 1. 自動バックアップでバイナリログを有効にする
</div>

自動バックアップ機能の設定によって、MySQL のバイナリログの有効／無効が決まります。自動バックアップは、RDS Console で **Modify** > **Additional configuration** > **Backup** の順に進み、**Enable automated backups** チェックボックスを選択すると、対象のインスタンスで設定できます (まだ選択していない場合) 。

<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" />

レプリケーションの用途に応じて、**Backup retention period** は十分に長い値に設定することを推奨します。

<div id="binlog-retention-interval">
  ### 2. binlog の保持期間を延長する
</div>

<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) プロシージャを使用します。

[//]: # "注: ほとんどの CDC（変更データキャプチャ）プロバイダーは、RDS の最大保持期間（7 日間/168 時間）を推奨しています。これはディスク使用量に影響するため、ここでは控えめに最小 3 日間/72 時間を推奨しています。"

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

この設定がされていない場合や、間隔が短すぎる場合、バイナリログに欠落が生じ、ClickPipes でレプリケーションを再開できなくなるおそれがあります。

<div id="binlog-settings">
  ## binlog 設定を構成する
</div>

RDS Console で MySQL インスタンスをクリックし、**Configuration** タブに移動すると、パラメータグループを確認できます。

<Tip>
  MySQL クラスターを使用している場合、以下のパラメータは DB インスタンスグループではなく、[DB cluster](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_WorkingWithParamGroups.CreatingCluster.html) のパラメータグループで確認できます。
</Tip>

<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" />

<br />

パラメータグループのリンクをクリックすると、専用ページに移動します。右上に **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" />

以下のパラメータを次のように設定する必要があります。

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

[Global Transaction Identifiers (GTIDs)](https://dev.mysql.com/doc/refman/8.0/en/replication-gtids.html) は、MySQL でコミットされた各トランザクションに割り当てられる一意の ID です。これにより、binlog レプリケーションが簡素化され、トラブルシューティングも容易になります。MySQL ClickPipe が GTID ベースのレプリケーションを使用できるようにするため、GTID モードを有効にすることを **推奨** します。

GTID ベースのレプリケーションは、Amazon RDS for MySQL バージョン 5.7、8.0、8.4 でサポートされています。Aurora MySQL インスタンスで GTID モードを有効にするには、次の手順に従ってください。

1. RDS Console で 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-detect-table-modification/Qdrmbc1T54ihl0_n/images/integrations/data-ingestion/clickpipes/mysql/enable_gtid.webp?fit=max&auto=format&n=Qdrmbc1T54ihl0_n&q=85&s=50cea1734e160de210b989215ce4328a" 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. スキーマに対する権限を付与します。次の例は、`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="configure-network-access">
  ## ネットワークアクセスを設定する
</div>

<div id="ip-based-access-control">
  ### IPベースのアクセス制御
</div>

Aurora MySQL インスタンスへのトラフィックを制限するには、[ドキュメントに記載されている固定 NAT IP](/ja/integrations/clickpipes/home#list-of-static-ips) を、RDS のセキュリティグループの **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 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-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="上記のセキュリティグループのインバウンドルールを編集" 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 セットアップガイド](/ja/resources/support-center/knowledge-base/cloud-services/aws-privatelink-setup-for-clickpipes)に従ってください。

<div id="next-steps">
  ## 次のステップ
</div>

Amazon RDS MySQL インスタンスでの binlog レプリケーションと、ClickHouse Cloud への安全な接続の設定が完了したら、[最初の MySQL ClickPipe を作成](/ja/integrations/clickpipes/mysql/index#create-your-clickpipe)できます。MySQL CDC に関するよくある質問は、[MySQL のよくある質問ページ](/ja/integrations/clickpipes/mysql/faq)を参照してください。
