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聯結器。