Grant MySQL user privileges
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_passwordcaching_sha2_password(default for MySQL 8.0)
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:
-- 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:
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.
-
To check the user's authentication plugin, run the following SQL command. Replace
<user>with the user name.SQLSELECT user, host, plugin FROM mysql.user WHERE user = '<user>'; -
The query can return more than one row, one for each host. For each row whose
plugincolumn showsmysql_native_password, change the plugin. Replace<user>,<host>, and<password>with the user name, thehostvalue from that row, and the user's password.For MySQL 8.0 and above, run the following SQL command:
SQLALTER USER '<user>'@'<host>' IDENTIFIED WITH caching_sha2_password BY '<password>';For MySQL 5.7, run the following SQL command:
SQLALTER USER '<user>'@'<host>' IDENTIFIED WITH sha256_password BY '<password>';
Required privileges
Grant the following privileges to the replication user:
Privilege | Description |
|---|---|
| Required to read binary logs and track changes. |
| Required to access replication status and metadata. |
| Required to validate the authentication plugin. You can grant either |
| Required to read initial snapshots and table metadata. |
Grant statements
Run the following SQL commands to grant the required privileges:
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:
SHOW GRANTS FOR 'lakeflow_connect_user'@'%';
The output includes the following:
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: