tableEnv.executeSql("create table mysql_binlog(\n "+
"id STRING not null,\n"+
"region_name STRING ,\n"+
"primary key(id) NOT ENFORCED \n"+ //两个条件缺一不可
")with(\n"+
"'connector'='mysql-cdc',\n"+
"'hostname'='192.168.56.131',\n"+
"'port'='3306',\n"+
"'username'='root',\n"+
"'password'='root123456',\n"+
"'database-name'='gmail',\n"+
"'table-name'='base_region',\n"+
"'server-time-zone'='GMT-4',\n"+
"'scan.startup.mode'='initial',\n"+
"'scan.incremental.snapshot.enabled'='true');\n"); // 两个条件缺一不可
如果数据源mysql表中中设置了主键,那么链接时,需要添加上面两个参数,并且两个条件缺一不可
否则报错:
Recovery is suppressed by NoRestartBackoffTime Strategy 主键冲突
如果mysql没有设置主键,with里面要加'scan.incremental.snapshot.enabled' = 'false'否则会报错:
如果mysql设置主键,with里面要加'scan.incremental.snapshot.enabled' = 'true'否则同样会报错:
[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.api.ValidationException: The primary key is necessary when enable 'Key: 'scan.incremental.snapshot.enabled' , default: true (fallback keys: [])' to 'true'
————————————————
版权声明:本文为CSDN博主「lbship」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lbship/article/details/114839662
文末再附上flinkcdc链接mysqlcdc的with参数
chunk-key.even-distribution.factor.lower-bound
chunk-key.even-distribution.factor.upper-bound
chunk-meta.group.size
connect.max-retries
connect.timeout
connection.pool.size
connector
database-name
heartbeat.interval
hostname
password
port
property-version
scan.incremental.snapshot.chunk.key-column
scan.incremental.snapshot.chunk.size
scan.incremental.snapshot.enabled
scan.newly-added-table.enabled
scan.snapshot.fetch.size
scan.startup.mode
scan.startup.specific-offset.file
scan.startup.specific-offset.gtid-set
scan.startup.specific-offset.pos
scan.startup.specific-offset.skip-events
scan.startup.specific-offset.skip-rows
scan.startup.timestamp-millis
server-id
server-time-zone
split-key.even-distribution.factor.lower-bound
split-key.even-distribution.factor.upper-bound
table-name
username
具体报错可以以上为参考
参考文献
https://blog.csdn.net/weixin_42133361/article/details/122299099
https://blog.csdn.net/lbship/article/details/114839662