1.源:
SQLSERVER 配置只读权限的帐号和密码:
2.源表结构:
CREATE TABLE [dbo].[EgOrg_Company](
[CmpCode] [varchar](30) NOT NULL, String
[CompanyName] [varchar](100) NULL, String
[ShortName] [varchar](100) NULL, String
[ParentCompanyCode] [varchar](30) NULL, String
[Deep] [int] NULL, Int32
[DeepPath] [varchar](8000) NULL, String
[Sort] [int] NULL, Int32
[Remark] [varchar](2000) NULL, String
[FlagDel] [bit] NULL, Int32
[CmpType] [int] NULL, Int32
[ResOwner] [varchar](30) NULL, String
CONSTRAINT [PK_EGORG_COMPANY] PRIMARY KEY CLUSTERED
3.目标:clickhouse 配置读写帐号和创建需要同步的表结构,注意:DATAX同步不会在目标库中创建源表结构,需要手动创建表结构
在clickhouse中创建表结构:
CREATE TABLE EgOrg_Company( CmpCode String,CompanyName String,ShortName String,ParentCompanyCode String,Deep Int32, DeepPath String, Sort Int32 , Remark String,FlagDel String,CmpType Int32,ResOwner String ) ENGINE = MergeTree() ORDER BY CmpCode
4.编写JSON配置文件:
/usr/local/datax/job/sqlserver_to_clickhouse.json
[root@node101 job]# cat sqlserver_to_clickhouse.json
{
"job": {
"setting": {
"speed": {
"byte": 1048576
}
},
"content": [
{
"reader": {
"name": "sqlserverreader",
"parameter": {
"username": "sa",
"password": "123456",
"mandatoryEncoding":"gb2312",
"connection": [
{
"jdbcUrl": ["jdbc:sqlserver://172.16.1.144:1433;DatabaseName=test;"],
"querySql":["select * from test.dbo.EgOrg_Company"]
}
]
}
},
"writer": {
"name": "clickhousewriter",
"parameter": {
"username": "default",
"password": "123456",
"column": ["*"],
"connection": [
{
"jdbcUrl": "jdbc:clickhouse://172.16.1.220:8123/sqlserver",
"table": ["EgOrg_Company"]
}
],
"preSql": [],
"postSql": [],
"batchSize": 65536,
"batchByteSize": 134217728,
"dryRun": false,
"writeMode": "insert"
}
}
}
]
}
}
[root@node101 datax]# ./bin/datax.py ./job/sqlserver_to_clickhouse.json
2022-03-12 17:19:38.860 [job-0] INFO JobContainer -
任务启动时刻 : 2022-03-12 17:19:27
任务结束时刻 : 2022-03-12 17:19:38
任务总计耗时 : 11s
任务平均流量 : 60B/s
记录写入速度 : 0rec/s
读出记录总数 : 6
读写失败总数 : 0
5.到clickhosue中查看数据: