---
title: Grant MySQL user privileges
description: Grant the MySQL replication user the privileges that Lakeflow Connect needs to read table data and binary logs for ingestion into Databricks.
canonical_url: https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-privileges
---

# Grant MySQL user privileges

> [!NOTE]
>
> This page contains references to the term *slave*, a term that Databricks doesn't use. When the term is removed from the third-party software, we'll remove it from this page.

This page lists the privileges that the MySQL replication user needs for Lakeflow Connect ingestion, with the SQL to create the user and grant them.

Databricks recommends that you create a dedicated MySQL user solely for Databricks ingestion. This user requires specific privileges to read table data and access binary logs for change data capture.

## <a id="auth" />Authentication methods

The MySQL connector supports the following authentication plugins based on your MySQL version:

**MySQL 5.7.44 and later:**

* `sha256_password`

**MySQL 8.0 and later:**

* `sha256_password`
* `caching_sha2_password` (default for MySQL 8.0)

> [!NOTE]
>
> If you use `sha256_password` or `caching_sha2_password`, the **Test Connection** button in the Databricks UI might fail even with valid credentials. This is a known limitation. You can still create the connection and proceed with pipeline setup.

The connector doesn't support `mysql_native_password`. To check and change the plugin of an existing user, see [Change the authentication plugin of an existing user](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-privileges.md#change-plugin).

## <a id="create-user" />Create the replication user

To create a dedicated MySQL user for replication, run the following SQL commands on your MySQL database:

```sql
-- For MySQL version >= 8.x
CREATE USER 'lakeflow_connect_user'@'%' IDENTIFIED WITH caching_sha2_password BY 'StrongP@ssw0rd!';

-- For MySQL version 5.7.x
CREATE USER 'lakeflow_connect_user'@'%' IDENTIFIED WITH sha256_password BY 'StrongP@ssw0rd!';
```

Replace `StrongP@ssw0rd!` with a strong password. The `%` wildcard allows connections from any host. For better security, replace `%` with the specific IP ranges or hostnames that Databricks will use to connect.

## <a id="change-plugin" />Change the authentication plugin of an existing user

If you use an existing user for replication, make sure that it doesn't use the `mysql_native_password` plugin. With that plugin, change data capture fails with the `INGESTION_GATEWAY_SOURCE_CONNECTION_FAILURE` error class and the following message, even if **Test Connection** succeeds or you continued past its failure:

```output
Authorization failed for user: <user>. Please ensure the user exists with correct credentials and that either the 'sha256_password' or 'caching_sha2_password' authentication plugin is enabled.
```

Changing the plugin affects every client that logs in as this user. Older drivers, and clients that connect without TLS or RSA key exchange, might stop working. To avoid this, use a dedicated replication user. See [Create the replication user](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-privileges.md#create-user). If you set a new password, also update the credentials in the Unity Catalog connection.

Run the following statements as an administrative user.

1. To check the user's authentication plugin, run the following SQL command. Replace `<user>` with the user name.

   ```sql
   SELECT user, host, plugin FROM mysql.user WHERE user = '<user>';
   ```

2. The query can return more than one row, one for each host. For each row whose `plugin` column shows `mysql_native_password`, change the plugin. Replace `<user>`, `<host>`, and `<password>` with the user name, the `host` value from that row, and the user's password.

   For MySQL 8.0 and above, run the following SQL command:

   ```sql
   ALTER USER '<user>'@'<host>' IDENTIFIED WITH caching_sha2_password BY '<password>';
   ```

   For MySQL 5.7, run the following SQL command:

   ```sql
   ALTER USER '<user>'@'<host>' IDENTIFIED WITH sha256_password BY '<password>';
   ```

## <a id="privileges" />Required privileges

Grant the following privileges to the replication user:

| Privilege                                    | Description                                                                                                                             |
| -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `REPLICATION SLAVE`                          | Required to read binary logs and track changes.                                                                                         |
| `REPLICATION CLIENT`                         | Required to access replication status and metadata.                                                                                     |
| `SELECT(plugin, user)` on `mysql.user` table | Required to validate the authentication plugin. You can grant either `SELECT(plugin, user)` or full `SELECT` on the `mysql.user` table. |
| `SELECT` on target databases and tables      | Required to read initial snapshots and table metadata.                                                                                  |

## <a id="grant" />Grant statements

Run the following SQL commands to grant the required privileges:

```sql
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'lakeflow_connect_user'@'%';

GRANT SELECT(plugin,user) ON mysql.user TO 'lakeflow_connect_user'@'%';

-- Grant select privilege on all user tables
GRANT SELECT ON *.* TO 'lakeflow_connect_user'@'%';

FLUSH PRIVILEGES;
```

## <a id="verify" />Verify user privileges

To verify that the user has the correct privileges, run the following command:

```sql
SHOW GRANTS FOR 'lakeflow_connect_user'@'%';
```

The output includes the following:

```sql
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'lakeflow_connect_user'@'%'
GRANT SELECT (`plugin`, `user`) ON `mysql`.`user` TO 'lakeflow_connect_user'@'%'
GRANT SELECT ON *.* TO 'lakeflow_connect_user'@'%'
```

## <a id="additional-resources" /> Additional resources

After creating the replication user, configure your MySQL server for binlog replication. The configuration steps vary by deployment type:

* [AWS RDS and Aurora MySQL](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-aws-rds-config.md)
* [Azure Database for MySQL](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-azure-config.md)
* [MySQL on EC2 or VM](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-ec2-config.md)
* [Google Cloud SQL for MySQL](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/mysql-gcp-config.md)
