> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hightouch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MySQL

> Power internal tools, in-app experiences, and more

## Overview

This destination combines the analytical power of your data warehouse with the low-latency performance of a transactional database.

## Supported syncing

| Sync Type | Description | Supported Sync Modes |
| - | - | - |
| **Table** | Sync data from any source to a MySQL table | Upsert |

For more information about sync modes, refer to the [sync modes](https://docs.hightouch.com/syncs/types-and-modes.md#sync-modes) docs.

## Connect to MySQL

> [!NOTE]
>
> You may need to allowlist Hightouch's IP addresses to let our systems connect to your MySQL instance. Reference our [networking docs](https://docs.hightouch.com/security/networking#ip-addresses) to determine which IP addresses you need to allowlist.
>
> You can also securely connect to your MySQL instance using [AWS PrivateLink](https://docs.hightouch.com/security/aws/privatelink.md) or [GCP Private Service Connect](https://docs.hightouch.com/security/gcp/private-service-connect.md). AWS PrivateLink and GCP Private Service Connect are [Business Tier](https://hightouch.com/pricing) features.

Go to the [**Destinations** overview page](https://app.hightouch.com/destinations?from=docs) and click the **Add destination** button. Select **MySQL** and click **Continue**.

Enter the following required fields into Hightouch:

* **Host**: The hostname or IP address of your MySQL.
* **Port**: The port number of your MySQL. The default is 3306, but yours may be different.
* **Database**: The name of the database in your MySQL.
* **User**: This can be your personal MySQL login or a dedicated user for Hightouch.
* **Password**: The password for the user specified above.

You can optionally create or select a [previously configured tunnel](https://docs.hightouch.com/security/ssh-tunneling.md) or upload a `.pem` CA certificate.

### SSH tunneling

Hightouch can connect directly to MySQL over the public internet or via an SSH tunnel. Since data is encrypted in transit via TLS, a direct connection is suitable for most use cases. You may need to set up a tunnel if your MySQL instance is on a private network or virtual private cloud (VPC).

Hightouch supports both standard and reverse SSH tunnels. To learn more about SSH tunneling, refer to Hightouch's [tunneling documentation](https://docs.hightouch.com/security/ssh-tunneling.md).

## Sync configuration

Once you've set up your MySQL destination and have a [model](https://docs.hightouch.com/getting-started/concepts.md#models) to pull data from, you can set up your sync configuration to begin syncing data. Go to the [**Syncs** overview page](https://app.hightouch.com/syncs?from=docs) and click the **Add sync** button to begin. Then, select the relevant model and the MySQL destination you want to sync to.

### Select table

Select the existing table in MySQL you want to sync to.

### Record matching

You can match rows from your model to rows in MySQL on any column as long as it is a [primary key or unique key](https://dev.mysql.com/doc/refman/8.0/en/partitioning-limitations-partitioning-keys-unique-keys.html).

### Field mapping

Select which model columns you want to sync to your MySQL table columns. Hightouch automatically pulls the columns from your table to make them available for you to map.

> [!TIP]
>
> When syncing to [binary](https://dev.mysql.com/doc/refman/8.0/en/binary-varbinary.html) destination fields, Hightouch assumes the model column values to be [base64](https://en.wikipedia.org/wiki/Base64) strings. If they aren't, you can use [template mapping](https://docs.hightouch.com/syncs/mapping-data.md#template-mapping) to [cast](https://docs.hightouch.com/models/data-types-casting.md#casting) them if needed.
>
> ![Base 64 template mapping](https://mintcdn.com/hightouch-3c037897/L_vQfA0JQEpeGUUo/images/mapping-data/base-64-mapping.png?fit=max\&auto=format\&n=L_vQfA0JQEpeGUUo\&q=85\&s=71ec8c496160ad1cc4762788993dacb6)

### Upsert query optimization

You can choose to use the [`LOAD DATA` statement](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_local_infile) in the upsert query during your sync. This option loads data from a text file into your database, which can be up to twenty times faster than the default `INSERT INTO` query Hightouch uses.

If you enable the `LOAD DATA` option, Hightouch replaces databases rows with the mapped model row, if it exists. This means that if any MySQL fields aren't mapped in Hightouch they receive `NULL` values.

For Hightouch to successfully sync with the `LOAD DATA` option, you need to enable the [`local_infile`](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_local_infile) system variable.

> [!WARNING]
>
> Review the [security considerations](https://dev.mysql.com/doc/refman/8.0/en/load-data-local-security.html) before enabling `local_infile`.

### Delete behavior

When rows no longer shows up from your model's query results, you can configure the sync to **Do nothing** or **Delete** those rows from the MySQL.

| Behavior | Description |
| - | - |
| **Do nothing** | Keep the synced rows in the table in MySQL |
| **Delete** | Delete the synced rows from the table in MySQL |

## Tips and troubleshooting

To see the exact API requests and responses from each sync run, use the [live debugger](https://docs.hightouch.com/syncs/debugger.md). To get notified by Slack, PagerDuty, SMS, or email when a sync fails, set up [sync alerts](https://docs.hightouch.com/syncs/alerting.md). If you run into an issue this page doesn't cover, [contact support](#pylon-chat).
