Skip to main content

Grant MySQL user privileges

info

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.

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.

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.

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. 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>';

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.

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.

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;

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'@'%'

Additional resources​

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