[问题踩坑]Flink SQL CDC维表查询异常:User does not have the ‘LOCK TABLES‘ privilege required to obtain a ……
Posted 白夜鸦羽
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[问题踩坑]Flink SQL CDC维表查询异常:User does not have the ‘LOCK TABLES‘ privilege required to obtain a ……相关的知识,希望对你有一定的参考价值。
背景
使用Flink SQL CDC模式创建维表如下
CREATE TABLE cdc_test
(
id STRING,
ip STRING,
url STRING,
PRIMARY KEY (id) NOT ENFORCED
) WITH (
'connector' = 'mysql-cdc', -- Flink 1.11之后才支持
'hostname' = '127.0.0.1',
'port' = '3306',
'database-name' = 'shadow-db',
'table-name' = 'cdc',
'username' = 'shadow',
'password' = 'shadow@csdn'
);
查询该维表数据
SELECT * FROM cdc_test;
任务无法运行,抛出异常 User does not have the 'LOCK TABLES' privilege required to obtain a consistent snapshot by preventing concurrent writes to tables.
原因
连接MySQL的用户缺乏必要的CDC权限。
Flink SQL CDC基于Debezium实现。当启动MySQL CDC源时,它将获取一个全局读取锁(FLUSH TABLES WITH READ LOCK),该锁将阻止其他数据库的写入,然后读取当前binlog位置以及数据库和表的schema,之后将释放全局读取锁。然后它扫描数据库表并从先前记录的位置读取binlog,Flink将定期执行checkpoints以记录binlog位置。如果发生故障,作业将重新启动并从checkpoint完成的binlog位置恢复,因此它保证了仅一次的语义。
解决
创建一个新的MySQL用户并授予其必要的权限
mysql> CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'user' IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;
参考
以上是关于[问题踩坑]Flink SQL CDC维表查询异常:User does not have the ‘LOCK TABLES‘ privilege required to obtain a ……的主要内容,如果未能解决你的问题,请参考以下文章
[问题踩坑]Flink 1.11.1 SQL View中UDTF调用异常 Column ‘xxx‘ not found in any table
[问题踩坑]Flink 1.11.1 SQL View中UDTF调用异常 Column ‘xxx‘ not found in any table