1,关于Flink cdc的使用说明
1)导入依赖
<dependency>
<groupId>com.alibaba.ververica</groupId>
<artifactId>flink-connector-mysql-cdc</artifactId>
<version>1.1.0</version>
</dependency>
sql案例 :
2)需要理解注意的地方
这个锁可以去掉的,如果不去掉,也是很轻量级的,并不是snapshot完后才释放,而是拿到当前的binlog位点后就释放掉了。
如果表结构 不会变更的话可以完全禁用掉这个锁的。在sql里加上 'debezium.snapshot.locking.mode' = 'none' 就可以了
问题:使用cdc的时候会影响mysql的性能跟正常使用吗?
不会,这个锁应该很快就能释放,没什么性能瓶颈,但是得保证你接binlog的用户开了reload权限
请百度 ‘’mysql的reload权限‘
2,官网的案例代码
package cdc; /** * @program: flink-neiwang-dev * @description: 通过cdc代码读取mysql的数据 * @author: Mr.Wang * @create: 2020-10-21 15:29 **/ import com.alibaba.fastjson.JSONObject; import com.alibaba.ververica.cdc.connectors.mysql.MySQLSource; import org.apache.flink.streaming.api.datastream.DataStreamSource; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; import org.apache.flink.streaming.api.functions.source.SourceFunction; public class MySqlBinlogSourceExample { public static void main(String[] args) { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(1); SourceFunction<JSONObject> sourceFunction = MySQLSource.<JSONObject>builder() .hostname("192.168.x.xx") .port(3306) .databaseList("cdc_test") // monitor all tables under inventory database .username("root") .password("xxxxxx") .deserializer(new CdcDwdDeserializationSchema()) // converts SourceRecord to String .build(); DataStreamSource<JSONObject> stringDataStreamSource = env.addSource(sourceFunction); stringDataStreamSource.print("===>"); try { env.execute("测试mysql-cdc"); } catch (Exception e) { e.printStackTrace