1, 需求
2, flinksql编写
- 除常用的MySQL, Derby, PostgreSQL,其他关系型数据库需要下载jdbc驱动,放在 Flink 的 lib/ 目录中
CREATE TABLE IF NOT EXISTS kafkatab1 (
`@@id` STRING,
`@message` STRING,
`@ip` STRING,
`@hostname` STRING,
`@path` STRING
) WITH (
'connector' = 'kafka',
'topic' = 'test1',
'scan.startup.mode' = 'latest-offset',
'properties.bootstrap.servers' = '192.168.56.1:9092',
'format' = 'json'
);
create table t1(
id STRING,
message STRING,
ip string,
hostname string,
path string,
primary key(id) not enforced
)with(
'connector'='jdbc',192.168.56.1:3306/test1',
'username'='root',
'password'='123456',
'table-name'='t1'
);
insert into t1(id, message, ip, hostname, path )
select `@@id`,`@message`, `@ip` ,`@hostname`,`@path` from kafkatab1;