报错内容
Flink CDC 读取 MySQL 的用户有需要表的读写权限,但是报错。
less
io.debezium.DebeziumException: Access denied; you need (at least one of) the REPLICATION SLAVE privilege(s) for this operation Error code: 1227; SQLSTATE: 42000.
at io.debezium.connector.mysql.MySqlStreamingChangeEventSource.wrap(MySqlStreamingChangeEventSource.java:1489) ~[flink-1.0.jar:?]
at io.debezium.connector.mysql.MySqlStreamingChangeEventSource$ReaderThreadLifecycleListener.onCommunicationFailure(MySqlStreamingChangeEventSource.java:1545) [flink-1.0.jar:?]
at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:1079) [flink-1.0.jar:?]
at com.github.shyiko.mysql.binlog.BinaryLogClient.connect(BinaryLogClient.java:631) [flink-1.0.jar:?]
at com.github.shyiko.mysql.binlog.BinaryLogClient$7.run(BinaryLogClient.java:932) [flink-1.0.jar:?]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_202]
Caused by: com.github.shyiko.mysql.binlog.network.ServerException: Access denied; you need (at least one of) the REPLICATION SLAVE privilege(s) for this operation
at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:1043) ~[flink-1.0.jar:?]
... 3 more
问题原因
错误信息提示你需要REPLICATION SLAVE
权限。这个权限允许用户从MySQL主服务器复制(读取)二进制日志,这是进行MySQL复制所必须的权限。在你的情况下,Flink的Debezium connector正在尝试读取二进制日志以获取数据库的变更事件,因此需要这个权限。
解决方法
sql
GRANT REPLICATION CLIENT ON *.* TO 'flink'@'%';
GRANT REPLICATION SLAVE ON *.* TO 'flink'@'%';
FLUSH PRIVILEGES;
REPLICATION CLIENT
权限允许用户查询主服务器的二进制日志状态(通过SHOW MASTER STATUS
命令)和从服务器的状态(通过SHOW SLAVE STATUS
命令)。这个权限通常用于监控和管理MySQL的主从复制。
REPLICATION SLAVE
权限允许用户从主服务器复制(读取)二进制日志。这是进行MySQL复制所必需的权限,也是Flink的Debezium connector需要的权限。MySQL中,
REPLICATION CLIENT
和REPLICATION SLAVE
是全局级别的权限,不能被授予特定的数据库或表