Back to Materialize

Ingest data from Google Cloud SQL

doc/user/content/ingest-data/mysql/google-cloud-sql.md

1236.2 KB
Original Source

This page shows you how to stream data from Google Cloud SQL for MySQL to Materialize using theMySQL source.

{{< tip >}} {{< guided-tour-blurb-for-ingest-data >}} {{< /tip >}}

Before you begin

{{% mysql-direct/before-you-begin %}}

A. Configure Google Cloud SQL

1. Enable GTID-based binlog replication

Before creating a source in Materialize, you must configure Google Cloud SQL for MySQL for GTID-based binlog replication. Ensure the upstream MySQL database has been configured for GTID-based binlog replication:

{{% mysql-direct/ingesting-data/mysql-configs %}}

For guidance on enabling GTID-based binlog replication in Cloud SQL, see the Cloud SQL documentation.

2. Create a user for replication

{{% mysql-direct/create-a-user-for-replication %}}

B. (Optional) Configure network security

{{< note >}} If you are prototyping and your Google Cloud SQL instance is publicly accessible, you can skip this step. For production scenarios, we recommend configuring one of the network security options below. {{< /note >}}

{{< tabs >}}

{{< tab "Cloud">}}

There are various ways to configure your database's network to allow Materialize to connect:

  • Allow Materialize IPs: If your database is publicly accessible, you can configure your database's firewall to allow connections from a set of static Materialize IP addresses.

  • Use an SSH tunnel: If your database is running in a private network, you can use an SSH tunnel to connect Materialize to the database.

Select the option that works best for you.

{{< tabs >}}

{{< tab "Allow Materialize IPs">}}

  1. In the SQL Shell, or your preferred SQL client connected to Materialize, find the static egress IP addresses for the Materialize region you are running in:

    mzsql
    SELECT * FROM mz_egress_ips;
    
  2. Update your Google Cloud SQL firewall rules to allow traffic from each IP address from the previous step.

{{< /tab >}}

{{< tab "Use an SSH tunnel">}}

To create an SSH tunnel from Materialize to your database, you launch an instance to serve as an SSH bastion host, configure the bastion host to allow traffic only from Materialize, and then configure your database's private network to allow traffic from the bastion host.

  1. Launch a GCE instance to serve as your SSH bastion host.

    • Make sure the instance is publicly accessible and in the same VPC as your database.
    • Add a key pair and note the username. You'll use this username when connecting Materialize to your bastion host.
    • Make sure the VM has a static public IP address. You'll use this IP address when connecting Materialize to your bastion host.
  2. Configure the SSH bastion host to allow traffic only from Materialize.

    1. In the SQL Shell, or your preferred SQL client connected to Materialize, get the static egress IP addresses for the Materialize region you are running in:

      mzsql
      SELECT * FROM mz_egress_ips;
      
    2. Update your SSH bastion host's firewall rules to allow traffic from each IP address from the previous step.

  3. Update your Google Cloud SQL firewall rules to allow traffic from the SSH bastion host.

{{< /tab >}}

{{< /tabs >}}

{{< /tab >}}

{{< tab "Self-Managed">}}

{{% include-md file="shared-content/self-managed/configure-network-security-intro.md" %}}

{{< tabs >}}

{{< tab "Allow Materialize IPs">}}

  1. Update your Google Cloud SQL to allow traffic from Materialize IPs.

{{< /tab >}}

{{< tab "Use an SSH tunnel">}}

To create an SSH tunnel from Materialize to your database, you launch an instance to serve as an SSH bastion host, configure the bastion host to allow traffic only from Materialize, and then configure your database's private network to allow traffic from the bastion host.

  1. Launch a GCE instance to serve as your SSH bastion host.

    • Make sure the instance is publicly accessible and in the same VPC as your database.
    • Add a key pair and note the username. You'll use this username when connecting Materialize to your bastion host.
    • Make sure the VM has a static public IP address. You'll use this IP address when connecting Materialize to your bastion host.
  2. Configure the SSH bastion host to allow traffic only from Materialize.

  3. Update your Google Cloud SQL firewall rules to allow traffic from the SSH bastion host.

{{< /tab >}}

{{< /tabs >}}

{{< /tab >}}

{{< /tabs >}}

C. Ingest data in Materialize

1. (Optional) Create a cluster

{{< note >}} If you are prototyping and already have a cluster to host your MySQL source (e.g. quickstart), you can skip this step. For production scenarios, we recommend separating your workloads into multiple clusters for resource isolation. {{< /note >}}

{{% mysql-direct/create-a-cluster %}}

2. Create a connection

Once you have configured your network, create a connection in Materialize per your networking configuration.

{{< tabs >}}

{{< tab "Allow Materialize IPs">}} {{% mysql-direct/ingesting-data/allow-materialize-ips %}} {{< /tab >}}

{{< tab "Use an SSH tunnel">}} {{% mysql-direct/ingesting-data/use-ssh-tunnel %}} {{< /tab >}}

{{< /tabs >}}

3. Start ingesting data

{{% include-example file="examples/ingest_data/mysql/create_source_cloud" example="create-source" %}}

{{% include-example file="examples/ingest_data/mysql/create_source_cloud" example="create-source-options" %}}

{{% include-example file="examples/ingest_data/mysql/create_source_cloud" example="schema-changes" %}}

4. Monitor the ingestion status

{{% mysql-direct/check-the-ingestion-status %}}

5. Right-size the cluster

{{% mysql-direct/right-size-the-cluster %}}

D. Explore your data

{{% mysql-direct/next-steps %}}

Considerations

{{% include-headless "/headless/mysql-considerations" %}}