---
title: Create a gateway-based MySQL ingestion pipeline
description: Create a gateway-based MySQL pipeline in Lakeflow Connect with an ingestion gateway. Public Preview for existing customers. New customers use integrated CDC.
canonical_url: https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-pipeline
---

# Create a gateway-based MySQL ingestion pipeline

> [!NOTE]
> **Preview**
>
> The gateway-based pipeline for MySQL is in Public Preview and isn't available to new customers. It doesn't receive new features. To create a new pipeline, use an integrated change data capture (CDC) pipeline. See [Create an integrated CDC pipeline for MySQL](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-integrated-pipeline.md). To migrate an existing gateway-based pipeline to integrated CDC, contact your Databricks account team.

Use a gateway-based Lakeflow Connect pipeline to ingest data from MySQL into Databricks. The ingestion gateway extracts snapshot and change data from the source database, and the ingestion pipeline applies it to destination tables. The MySQL connector supports Amazon RDS for MySQL, Aurora MySQL, Azure Database for MySQL, Google Cloud SQL for MySQL, and MySQL running on EC2.

## Requirements

* To create an ingestion gateway and an ingestion pipeline, you must meet the following requirements:

  * Your workspace is enabled for Unity Catalog.

  * Serverless compute is enabled for your workspace. See [Serverless compute requirements](https://docs.databricks.com/aws/en/compute/serverless/index.md#requirements).

  * If you plan to create a connection: You have `CREATE CONNECTION` privileges on the metastore. See [Manage privileges in Unity Catalog](https://docs.databricks.com/aws/en/data-governance/unity-catalog/manage-privileges/index.md).

    If your connector supports UI-based pipeline authoring, you can create the connection and the pipeline at the same time by completing the steps on this page. However, if you use API-based pipeline authoring, you must create the connection in Catalog Explorer before you complete the steps on this page. See [Connect to managed ingestion sources](https://docs.databricks.com/aws/en/connect/managed-ingestion.md).

  * If you plan to use an existing connection: You have `USE CONNECTION` privileges or `ALL PRIVILEGES` on the connection.

  * You have `USE CATALOG` privileges on the target catalog.

  * You have `USE SCHEMA`, `CREATE TABLE`, and `CREATE VOLUME` privileges on an existing schema or `CREATE SCHEMA` privileges on the target catalog.

  - Unrestricted permissions to create clusters, or a custom policy (API only). A custom policy for the gateway must meet the following requirements:

    * Family: Job Compute

    * Policy family overrides:

      ```
      {
        "cluster_type": {
          "type": "fixed",
          "value": "dlt"
        },
        "num_workers": {
          "type": "unlimited",
          "defaultValue": 1,
          "isOptional": true
        },
        "runtime_engine": {
          "type": "fixed",
          "value": "STANDARD",
          "hidden": true
        }
      }
      ```

    * The following compute policy enables Databricks to scale the ingestion gateway to meet the needs of your workload. The minimum requirement is 4 cores. However, for better snapshot extraction performance, Databricks recommends using larger instance types with more memory and CPU cores.

      ```json
      {
        "driver_node_type_id": {
          "type": "fixed",
          "value": "r5n.2xlarge"
        },
        "node_type_id": {
          "type": "fixed",
          "value": "m5n.large"
        }
      }
      ```

    For more information about cluster policies, see [Select a compute policy](https://docs.databricks.com/aws/en/ldp/configure-compute.md#cluster-policy).

* To ingest from MySQL, you must also complete the [source setup](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-source-setup.md).

## <a id="using-databricks-ui" />Option 1: Databricks UI

Admin users can create a connection and a gateway-based pipeline at the same time in the UI.

1. In the sidebar of the Databricks workspace, click **Data Ingestion**.

2. On the **Add data** page, under **Databricks connectors**, click **MySQL**. The ingestion wizard opens.

3. On the **Ingestion gateway** page of the wizard, enter a unique name for the gateway.

4. Select a catalog and a schema for the staging ingestion data, then click **Next**.

5. On the **Ingestion pipeline** page, enter a unique name for the pipeline.

6. For **Destination catalog**, select a catalog to store the ingested data.

7. Select the Unity Catalog connection that stores the credentials required to access the source data.

   If there are no existing connections to the source, click **Create connection** to create a new connection. For instructions, see [Create a MySQL connection](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-connection.md). You must have `CREATE CONNECTION` privileges on the metastore.

   > [!NOTE]
   >
   > The **Test Connection** button might fail for MySQL users using `sha256_password` or `caching_sha2_password` authentication. This is a known limitation. You can still proceed with creating the connection.

8. Click **Create pipeline and continue**.

9. On the **Source** page, select the databases and tables to ingest.

10. Optionally change the default history tracking setting. For more information, see [Enable history tracking (SCD type 2)](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/scd.md).

11. Click **Next**.

12. On the **Destination** page, select the Unity Catalog catalog and schema to write to.

    If you don't want to use an existing schema, click **Create schema**. You must have `USE CATALOG` and `CREATE SCHEMA` privileges on the parent catalog.

13. Click **Save and continue**.

14. (Optional) On the **Settings** page, click **Create schedule**. Set the frequency to refresh the destination tables.

15. (Optional) Set email notifications for pipeline operation success or failure.

16. Click **Save and run pipeline**.

## Option 2: Programmatic interfaces

Before you ingest using Declarative Automation Bundles, Databricks APIs, Databricks SDKs, the Databricks CLI, or Terraform, you must have access to an existing Unity Catalog connection. For instructions, see [Create a MySQL connection](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-connection.md).

### Create the staging catalog and schema

The staging catalog and schema can be the same as the destination catalog and schema. The staging catalog can't be a foreign catalog.

```bash
export CONNECTION_NAME="my_mysql_connection"
export TARGET_CATALOG="main"
export TARGET_SCHEMA="lakeflow_mysql_connector"
export STAGING_CATALOG=$TARGET_CATALOG
export STAGING_SCHEMA=$TARGET_SCHEMA
export DB_HOST="mysql-instance.region.rds.amazonaws.com"
export DB_PORT="3306"
export DB_USER="databricks_replication"
export DB_PASSWORD="your_secure_password"

output=$(databricks connections create --json '{
  "name": "'"$CONNECTION_NAME"'",
  "connection_type": "MYSQL",
  "options": {
    "host": "'"$DB_HOST"'",
    "port": "'"$DB_PORT"'",
    "user": "'"$DB_USER"'",
    "password": "'"$DB_PASSWORD"'"
  }
}')

export CONNECTION_ID=$(echo $output | jq -r '.connection_id')
```

### Create the gateway and the ingestion pipeline

The ingestion gateway extracts snapshot and change data from the source database and stores it in a Unity Catalog staging volume. You must run the gateway as a continuous pipeline. This accommodates binlog retention policies on the source database.

The ingestion pipeline applies the snapshot and change data from the staging volume into destination streaming tables.

**Declarative Automation Bundles**

This tab describes how to deploy an ingestion pipeline using Declarative Automation Bundles. Bundles can contain YAML definitions of jobs and tasks, are managed using the Databricks CLI, and can be shared and run in different target workspaces (such as development, staging, and production). For more information, see [Declarative Automation Bundles](https://docs.databricks.com/aws/en/dev-tools/bundles/index.md).

1. Create a bundle using the Databricks CLI:

   ```bash
   databricks bundle init
   ```

2. Add two new resource files to the bundle:

   * A pipeline definition file (for example, `resources/mysql_pipeline.yml`).
   * A job definition file that controls the frequency of data ingestion (for example, `resources/mysql_job.yml`).

   The following is an example `resources/mysql_pipeline.yml` file:

   ```yaml
   variables:
     # Common variables used multiple places in the DAB definition.
     gateway_name:
       default: mysql-gateway
     dest_catalog:
       default: main
     dest_schema:
       default: ingest-destination-schema

   resources:
     pipelines:
       gateway:
         name: ${var.gateway_name}
         gateway_definition:
           connection_name: <mysql-connection>
           gateway_storage_catalog: main
           gateway_storage_schema: ${var.dest_schema}
           gateway_storage_name: ${var.gateway_name}
         catalog: ${var.dest_catalog}
         schema: ${var.dest_schema}

       pipeline_mysql:
         name: mysql-ingestion-pipeline
         ingestion_definition:
           ingestion_gateway_id: ${resources.pipelines.gateway.id}
           objects:
             # Modify this with your tables!
             - table:
                 # Ingest the table mydb.customers to dest_catalog.dest_schema.customers
                 source_schema: public
                 source_table: customers
                 destination_catalog: ${var.dest_catalog}
                 destination_schema: ${var.dest_schema}
             - schema:
                 # Ingest all tables in the mydb.sales schema to dest_catalog.dest_schema
                 # The destination table name will be the same as it is on the source
                 source_schema: sales
                 destination_catalog: ${var.dest_catalog}
                 destination_schema: ${var.dest_schema}
         catalog: ${var.dest_catalog}
         schema: ${var.dest_schema}
   ```

   The following is an example `resources/mysql_job.yml` file:

   ```yaml
   resources:
     jobs:
       mysql_dab_job:
         name: mysql_dab_job

         trigger:
           # Run this job every day, exactly one day from the last run
           # See https://docs.databricks.com/api/workspace/jobs/create#trigger
           periodic:
             interval: 1
             unit: DAYS

         email_notifications:
           on_failure:
             - <email-address>

         tasks:
           - task_key: refresh_pipeline
             pipeline_task:
               pipeline_id: ${resources.pipelines.pipeline_mysql.id}
   ```

3. Deploy the pipeline using the Databricks CLI:

   ```bash
   databricks bundle deploy
   ```

**Databricks notebook**

Update the `Configuration` cell in the following notebook with the source connection, target catalog, target schema, and tables to ingest from the source.

#### Create gateway and ingestion pipeline

[Get notebook](https://docs.databricks.com/notebooks/source/mysql-ingestion-pipeline.html)

**Databricks CLI**

To create the gateway:

```bash
export GATEWAY_PIPELINE_NAME="mysql-gateway"

output=$(databricks pipelines create --json '{
"name": "'"$GATEWAY_PIPELINE_NAME"'",
"catalog": "'"$STAGING_CATALOG"'",
"schema": "'"$STAGING_SCHEMA"'",
"gateway_definition": {
  "connection_id": "'"$CONNECTION_ID"'",
  "gateway_storage_catalog": "'"$STAGING_CATALOG"'",
  "gateway_storage_schema": "'"$STAGING_SCHEMA"'",
  "gateway_storage_name": "'"$GATEWAY_PIPELINE_NAME"'"
  }
}')

export GATEWAY_PIPELINE_ID=$(echo $output | jq -r '.pipeline_id')
```

To create the ingestion pipeline:

```bash
export INGESTION_PIPELINE_NAME="mysql-ingestion-pipeline"

databricks pipelines create --json '{
"name": "'"$INGESTION_PIPELINE_NAME"'",
"catalog": "'"$TARGET_CATALOG"'",
"schema": "'"$TARGET_SCHEMA"'",
"ingestion_definition": {
  "ingestion_gateway_id": "'"$GATEWAY_PIPELINE_ID"'",
  "objects": [
    {"table": {
        "source_schema": "public",
        "source_table": "customers",
        "destination_catalog": "'"$TARGET_CATALOG"'",
        "destination_schema": "'"$TARGET_SCHEMA"'",
        "destination_table": "customers"
        }},
     {"schema": {
        "source_schema": "sales",
        "destination_catalog": "'"$TARGET_CATALOG"'",
        "destination_schema": "'"$TARGET_SCHEMA"'"
        }}
    ]
  }
}'
```

**Terraform**

You can use Terraform to deploy and manage MySQL ingestion pipelines. For a complete example framework, including Terraform configurations for creating gateways and ingestion pipelines, see the [Lakeflow Connect Terraform examples](https://github.com/databricks-solutions/lakeflow-connect-terraform/) repository on GitHub.

## Additional resources

* [MySQL connector FAQ](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-faq.md)
* [MySQL connector limitations](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-limits.md)
* [MySQL connector reference](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-reference.md)
* [Troubleshoot MySQL ingestion issues](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-troubleshoot.md)
* [Common patterns for managed ingestion pipelines](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/common-patterns.md)
