Skip to content

Commit a61bac7

Browse files
sagarkapareseanzhougoogle
authored andcommitted
CDAP-17459 Use host name for user as '%' which means the user can connect to MySQL server from any host.
1 parent 7bceeb7 commit a61bac7

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

mysql-delta-plugins/docs/mysql-cdcSource.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ wait_timeout = <duration-in-seconds>
3838
A MySQL user must be defined with all the following permissions on any database which wants to be replicated:
3939
**SELECT**, **RELOAD**, **SHOW DATABASES**, **REPLICATION SLAVE** and **REPLICATION CLIENT**.
4040
```
41-
mysql> CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
42-
mysql> GRANT SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'user' IDENTIFIED WITH mysql_native_password BY 'password';
41+
mysql> CREATE USER 'user'@'%' IDENTIFIED BY 'password';
42+
mysql> GRANT SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'user'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
4343
mysql> FLUSH PRIVILEGES;
4444
```
4545

@@ -64,7 +64,8 @@ slave that is replicating from the server.
6464

6565
**Server Timezone:** Timezone of the MySQL server. This is used when converting dates into timestamps.
6666

67-
**User:** Username to use to connect to the MySQL server.
67+
**User:** Username to use to connect to the MySQL server. Actual account used by the source while connecting
68+
to the MySQL server will be of the form 'user_name'@'%' where user_name is this field.
6869

6970
**Password:** Password to use to connect to the MySQL server.
7071

mysql-delta-plugins/src/main/java/io/cdap/delta/mysql/MySqlConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public class MySqlConfig extends PluginConfig {
3333
@Description("Port to use to connect to the MySQL server.")
3434
private int port;
3535

36-
@Description("Username to use to connect to the MySQL server.")
36+
@Description("Username to use to connect to the MySQL server. Actual account used by the source while connecting " +
37+
"to the MySQL server will be of the form 'user_name'@'%' where user_name is this field.")
3738
private String user;
3839

3940
@Macro

mysql-delta-plugins/src/main/java/io/cdap/delta/mysql/MySqlTableAssessor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,12 @@ static ColumnEvaluation evaluateColumn(ColumnDetail detail) throws IllegalArgume
159159
}
160160

161161
private void checkReplicationPermissions(List<Problem> featureProblems, List<String> permissions) {
162-
String query = String.format("SHOW GRANTS FOR '%s'@'%s'", conf.getUser(), conf.getHost());
162+
String clientHost = "%";
163+
String query = String.format("SHOW GRANTS FOR '%s'@'%s'", conf.getUser(), clientHost);
163164
Problem permissionUnknownProblem =
164165
new Problem("Table Replication Permission Unknown",
165166
String.format("Unable to check if '%s' permissions were granted for user '%s'@'%s' or not",
166-
String.join(",", permissions), conf.getUser(), conf.getHost()),
167+
String.join(",", permissions), conf.getUser(), clientHost),
167168
"Check database connectivity and user permissions",
168169
"Change events might fail to be read after the snapshot phase");
169170
try (Connection connection = DriverManager.getConnection(conf.getJdbcURL(), conf.getConnectionProperties());
@@ -188,9 +189,9 @@ private void checkReplicationPermissions(List<Problem> featureProblems, List<Str
188189
featureProblems.add(
189190
new Problem("Table Replication Permission Not Granted",
190191
String.format("The '%s' permission is not granted for user '%s'@'%s'", permission,
191-
conf.getUser(), conf.getHost()),
192+
conf.getUser(), clientHost),
192193
String.format("Grant '%s' permission to user '%s'@'%s'", permission,
193-
conf.getUser(), conf.getHost()),
194+
conf.getUser(), clientHost),
194195
"Will not be able to read replication events after the initial snapshot completes."));
195196
}
196197
}

0 commit comments

Comments
 (0)