create database test;
use test;
- 离线数据源接入
CREATE TABLE ttab_source (
id INT,
name varchar(100),
PRIMARY KEY (id) NOT ENFORCED
) WITH (
'connector' = 'jdbc',
'url' = 'jdbc:sqlserver://xx.xx.40.186:1433;DatabaseName=test',
'table-name' = 'ttab',
'username' = 'sa',
'password' = '123456',
'driver' = 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
);
查看离线数据源(离线任务不会持续运行)
select * from ttab_source;
- 实时数据源接入
CREATE TABLE ttab_sourcer (
id INT,
name VARCHAR(100),
PRIMARY KEY (id) NOT ENFORCED
) WITH (
'connector' = 'sqlserver-cdc',
'hostname' = 'xx.xx.40.186',
'port' = '1433',
'username' = 'sa',
'password' = '123456',
'database-name' = 'test',
'table-name' = 'dbo.ttab'
);
查看实时数据源
select * from ttab_source;
实时数据源接入前,数据库及表必须先开启cdc
8.实时数据同步
CREATE TABLE ttab_sink (
id INT,
name varchar(100),
PRIMARY KEY (id) NOT ENFORCED
) WITH (
'connector' = 'jdbc',
'url' = 'jdbc:sqlserver://xx.xx.40.186:1433;DatabaseName=test',
'table-name' = 'ttab_sink',
'username' = 'sa',
'password' = '123456',
'driver' = 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
);
insert into ttab_sink select * from ttab_sourcer;
9.查看实时同步正常
离线同步把source换成jdbc连接器即可。
实时同步source需要时cdc连接器。