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

> Step-by-step guide on how to set up Cloud SQL for MySQL as a source for ClickPipes

# Cloud SQL for MySQL source setup guide

export const Image = ({img, alt, size}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

This is a step-by-step guide on how to configure your Cloud SQL for MySQL instance for replicating its data via the MySQL ClickPipe.

<h2 id="enable-binlog-retention-gcp">
  Enable binary log retention
</h2>

The binary log is a set of log files that contain information about data modifications made to an MySQL server instance, and binary log files are required for replication.

<h3 id="enable-binlog-logging-gcp">
  Enable binary logging via PITR
</h3>

The PITR feature determines whether binary logging is turned on or off for MySQL in Google Cloud. It can be set in the Cloud console, by editing your Cloud SQL instance and scrolling down to the below section.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/2Zeerd64Tl5ZAQUa/images/integrations/data-ingestion/clickpipes/mysql/source/gcp/gcp-mysql-pitr.png?fit=max&auto=format&n=2Zeerd64Tl5ZAQUa&q=85&s=3ff38799aaa57ca03541bb3951675624" alt="Enabling PITR in Cloud SQL" size="lg" border width="1622" height="1800" data-path="images/integrations/data-ingestion/clickpipes/mysql/source/gcp/gcp-mysql-pitr.png" />

Setting the value to a reasonably long value depending on the replication use-case is advisable.

If not already configured, make sure to set these in the database flags section by editing the Cloud SQL:

1. `binlog_expire_logs_seconds` to a value >= `86400` (1 day).
2. `binlog_row_metadata` to `FULL`
3. `binlog_row_image` to `FULL`

To do this, click on the `Edit` button in the top right corner of the instance overview page.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/2Zeerd64Tl5ZAQUa/images/integrations/data-ingestion/clickpipes/mysql/source/gcp/gcp-mysql-edit-button.png?fit=max&auto=format&n=2Zeerd64Tl5ZAQUa&q=85&s=975410975dd8948188c3399078c194ae" alt="Edit button in GCP MySQL" size="lg" border width="2174" height="570" data-path="images/integrations/data-ingestion/clickpipes/mysql/source/gcp/gcp-mysql-edit-button.png" />

Then scroll down to the `Flags` section and add the above flags.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/2Zeerd64Tl5ZAQUa/images/integrations/data-ingestion/clickpipes/mysql/source/gcp/gcp-mysql-flags.png?fit=max&auto=format&n=2Zeerd64Tl5ZAQUa&q=85&s=037387c0ed00250ed9e1438d5b593191" alt="Setting binlog flags in GCP" size="lg" border width="1174" height="1810" data-path="images/integrations/data-ingestion/clickpipes/mysql/source/gcp/gcp-mysql-flags.png" />

<h2 id="configure-database-user-gcp">
  Configure a database user
</h2>

Connect to your Cloud SQL MySQL instance as the root user and execute the following commands:

1. Create a dedicated user for ClickPipes:

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

2. Grant schema permissions. The following example shows permissions for the `clickpipes` database. Repeat these commands for each database and host you want to replicate:

   ```sql theme={null}
   GRANT SELECT ON `clickpipes`.* TO 'clickpipes_user'@'host';
   ```

3. Grant replication permissions to the user:

   ```sql theme={null}
   GRANT REPLICATION CLIENT ON *.* TO 'clickpipes_user'@'%';
   GRANT REPLICATION SLAVE ON *.* TO 'clickpipes_user'@'%';
   ```

<h2 id="configure-network-access-gcp-mysql">
  Configure network access
</h2>

If you want to restrict traffic to your Cloud SQL instance, please add the [documented static NAT IPs](/integrations/clickpipes/home#list-of-static-ips) to the allowlisted IPs of your Cloud SQL MySQL instance.
This can be done either by editing the instance or by heading over to the `Connections` tab in the sidebar in Cloud console.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/2Zeerd64Tl5ZAQUa/images/integrations/data-ingestion/clickpipes/mysql/source/gcp/gcp-mysql-ip.png?fit=max&auto=format&n=2Zeerd64Tl5ZAQUa&q=85&s=e1cbbd3b7989c19de040f797429d2d50" alt="IP allowlisting in GCP MySQL" size="lg" border width="1110" height="1598" data-path="images/integrations/data-ingestion/clickpipes/mysql/source/gcp/gcp-mysql-ip.png" />

<h2 id="download-root-ca-certificate-gcp-mysql">
  Download and use root CA certificate
</h2>

To connect to your Cloud SQL instance, you need to download the root CA certificate.

1. Go to your Cloud SQL instance in the Cloud console.
2. Click on `Connections` in the sidebar.
3. Click on the `Security` tab.
4. In the `Manage server CA certificates` section, click on the `DOWNLOAD CERTIFICATES` button at the bottom.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/2Zeerd64Tl5ZAQUa/images/integrations/data-ingestion/clickpipes/mysql/source/gcp/gcp-mysql-cert.png?fit=max&auto=format&n=2Zeerd64Tl5ZAQUa&q=85&s=2a974f67658678ccf70dcd061b211b96" alt="Downloading GCP MySQL Cert" size="lg" border width="1584" height="1098" data-path="images/integrations/data-ingestion/clickpipes/mysql/source/gcp/gcp-mysql-cert.png" />

5. In the ClickPipes UI, upload the downloaded certificate when creating a new MySQL ClickPipe.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/2Zeerd64Tl5ZAQUa/images/integrations/data-ingestion/clickpipes/mysql/source/gcp/rootca.png?fit=max&auto=format&n=2Zeerd64Tl5ZAQUa&q=85&s=b35ec2089934eba61bec2bdde0c02ee0" alt="Using GCP MySQL Cert" size="lg" border width="1636" height="1170" data-path="images/integrations/data-ingestion/clickpipes/mysql/source/gcp/rootca.png" />
