flink实时同步

DROP TABLE IF EXISTS `user_flink_primary_from`;
CREATE TABLE `user_flink_primary_from` (
 `id`  int(11) NOT NULL,
 `user_name` varchar(200) DEFAULT NULL,
 `create_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
 `age` int(3) DEFAULT NULL,
 `remark` varchar(200) DEFAULT NULL,
 PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

------------------------------------
DROP TABLE IF EXISTS `user_flink_primary_to`;
CREATE TABLE `user_flink_primary_to` (
 `id`  int(11) NOT NULL,
 `user_name` varchar(200) DEFAULT NULL,
 `create_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
 `age` int(3) DEFAULT NULL,
 `remark` varchar(200) DEFAULT NULL,
 PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

------------------------------------
#创建虚拟mysql表
CREATE TABLE user_flink_primary_from (
 id int,
 user_name string,
 create_time timestamp(3),
 age int,
 remark string,
 PRIMARY KEY (id) not ENFORCED
) WITH (
 'connector' =  'mysql-cdc',
 'hostname' = '172.22.46.34',
 'port' = '3306',
 'username'= 'root',
 'password' = 'xxx',
 'database-name' = 'flink', 
 'table-name' = 'user_flink_primary_from'
)

------------------------------------
#创建虚拟mysql表
CREATE TABLE user_flink_primary_to (
 id int,
 user_name string,
 create_time timestamp(3),
 age int,
 remark string,
 PRIMARY KEY (id) not ENFORCED
) WITH (
 'connector'=  'jdbc',
 'url' = 'jdbc:mysql://172.22.46.33:3306/flink?characterEncoding=utf8&useSSl=false&serverTimezone=Asia/Shanghai',
 'username'= 'root',
 'password' = 'xxx',
 'table-name' = 'user_flink_primary_to', 
 'driver' = 'com.mysql.jdbc.Driver',
 'scan.fetch-size' = '200'
)

------------------------------------

insert into user_flink_primary_to select * from user_flink_primary_from;

flink实时同步_第1张图片

flink实时同步_第2张图片

你可能感兴趣的:(flink,大数据)