创建mysql表:
CREATE TABLE `users` (
`id` int NOT NULL,
`name` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`age` int DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;
CREATE TABLE `users_his` (
`id` int NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`age` int DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;
jar包引入
下载地址:Maven Central Repository Search
flink 1.3.2_2.11
创建flink sql:
create table users (
`id` int ,
`name` String,
`age` int ,
PRIMARY KEY (id) NOT ENFORCED
) with (
'connector' = 'mysql-cdc',
'hostname' = '192.168.0.175',
'port' = '3306',
'username' = 'root',
'password' = '123456',
'database-name' = 'scs',
'table-name' = 'users'
);
create table users_his (
`id` int ,
`name` String,
`age` int ,
PRIMARY KEY (id) NOT ENFORCED
) with (
'connector' = 'jdbc',
'username' = 'root',
'password' = '123456',
'driver' = 'com.mysql.jdbc.Driver',
'table-name' = 'users_his',
'url' = 'jdbc:mysql://192.168.0.175:3306/scs?serverTimezone=UTC'
);
insert into users_his select id ,name,age from users;