# MySQL Reverse ETL Source

[MySQL](https://www.mysql.com/) is a popular open source relational DBMS.

RudderStack supports MySQL as a data source from which you can ingest data and route it to your desired downstream destinations.

{{< info >}}
This source is compatible with MySQL v8.0.0 and above.
{{< /info >}}

## Grant permissions {#granting-permissions}

Before you set up MySQL as a source, you must grant certain permissions on your MySQL database for RudderStack to access data from it.

Run the SQL queries listed in the following sections in the  **exact order** to grant these permissions:

### Step 1: Create user {#step-1-creating-the-user}

Create a new user `RUDDER` with a password `<password>` in MySQL:

```sql
CREATE USER RUDDER IDENTIFIED BY '<password>';
```

{{< warning >}}
Set a strong and unique password for creating the user in MySQL.
{{< /warning >}}

### Step 2: Create RudderStack schema and grant permissions {#creating-the-rudderstack-schema-and-granting-permissions}

1. Create a dedicated schema `_rudderstack`.

```sql
CREATE SCHEMA _rudderstack;
```

{{< warning >}}
The `_rudderstack` schema stores Reverse ETL sync state, snapshots, and related tables. **Do not change this name**.

See [`_rudderstack` Schema Reference]({{< ref "data-pipelines/reverse-etl/developer-guides/rudderstack-schema.md" >}}) for more details.
{{< /warning >}}

2. Grant full access to the schema `_rudderstack` for the user `RUDDER`.

```sql
GRANT ALL PRIVILEGES ON _rudderstack.* TO RUDDER;
```

### Step 3: Grant permissions on schema and table {#step-3-granting-permissions-on-your-schema-and-table}

1. Grant access to the user `RUDDER` to read data from tables in `<YOUR_SCHEMA>`:

```sql
GRANT SELECT ON  <YOUR_SCHEMA>.* TO RUDDER;
```

## Set up MySQL source in RudderStack {#setting-up-the-mysql-source-in-rudderstack}

1. Log in to your [RudderStack dashboard](https://app.rudderstack.com/).
2. On the **Connections** page, click **Add source**.
3. Under **Sources**, click **Reverse ETL** and select **MySQL**.

### Configure warehouse credentials {#configuring-the-connection-credentials}

You can choose to proceed with your existing warehouse credentials if you have configured them in the RudderStack dashboard previously. Otherwise, click **Add new credentials** to add new credentials for your warehouse.

- **Host**: Enter the host name of your MySQL instance.
- **Port**: Enter the port number associated with the MySQL database instance.
- **Database**: Enter the database name in your MySQL instance from where RudderStack ingests the data.
- **User**: Enter the user name of your MySQL instance.
- **Password**: Enter the password for the above user.
- **SSL Mode**: Select the SSL mode from **false** or **skip-verify** depending on how RudderStack should connect to your MySQL instance.

Click the **Verify** button on the top right. RudderStack will then [verify and validate your credentials](#faq). Once verified, click **Continue** to proceed.

### Specify name and source type

- **Source name**: Assign a name to uniquely identify the source in the RudderStack dashboard.
- **Select your source type**: RudderStack lets you set up a Reverse ETL source from a warehouse **Table** or **Model**.

| Source type | Description |
| :----| :---- |
| Table | Use an existing warehouse table as a data source. <br /><br />See [Use warehouse table as source](#use-warehouse-table-as-source) for detailed setup. |
| Model | Use custom SQL queries to fetch specific warehouse data and send them to your destinations. <br /><br />See [Use model as source](#use-model-as-source) for detailed setup. |

#### **Use warehouse table as source**

{{< customreadfile "/includes/retl/table-as-source.md" >}}

#### **Use model as source**

{{< customreadfile "/includes/retl/model-as-source.md" >}}

### Review and complete setup

{{< customreadfile "/includes/retl/review-retl-setup.md" >}}

## Connect destination

{{< customreadfile "/includes/retl/connect-retl-destination.md" >}}

## Update source configuration and settings

Go to the **Configuration** tab of your Reverse ETL source to update the configuration depending on your source type:

{{< warning >}}
You cannot change the source type on this page. 
{{< /warning >}}

{{< image src="images/retl-sources/update-source-configuration.webp" alt="Update source configuration" >}}

The below table lists the options you can update:

| Source type | Configurable options |
| :----| :-----| 
| Table | [Schema, Table, Primary key](#use-warehouse-table-as-source) |
| Model | <ul><li>[Model settings](#use-model-as-source)</li><li>[Primary key](#use-model-as-source)</li></ul>**Note**: You can set the primary key only after the SQL query runs successfully. |

{{< info >}}
After updating the configuration, the next sync will be a full sync.
{{< /info >}}

Go to the **Settings** tab to:

- Get your source ID.
- Change your warehouse credentials.
- [Set up custom alerts]({{< ref "monitor/alerts.md" >}}) for your Reverse ETL source.
- Delete the source permanently.

{{< warning >}}
You cannot delete a source that is connected to any destination.
{{< /warning >}}

{{< image src="images/retl-sources/source-settings.webp" alt="Edit source settings" >}}

## FAQ 

#### **What do the three validations under Verifying Credentials imply?**

When setting up a Reverse ETL source, you will see the following three validations under the **Verifying Credentials** option once you proceed after entering the warehouse credentials:

{{< image src="images/retl-sources/retl-credentials-validate.webp" alt="Validating credentials" >}}

These options are explained below:

- **Verifying Connection**: This option indicates that RudderStack is trying to connect to the warehouse with the provided warehouse credentials. 

{{< warning >}}
If this option gives an error, it means that one or more fields specified in the warehouse credentials are incorrect. Verify your credentials in this case.
{{< /warning >}}

- **Able to List Schema**: This option checks if RudderStack is able to fetch all schema details by using the provided credentials. 
- **Able to Access RudderStack Schema**: This option implies that RudderStack is able to access the `_rudderstack` schema you have created by running all commands in the [User Permissions](#creating-the-rudderstack-schema-and-granting-permissions) section.

{{< warning >}}
If this option gives an error, verify if you have successfully created the `_rudderstack` schema and given RudderStack the required permissions to access it.
{{< /warning >}}


