Datax介绍
官网: DataX/introduction.md at master · alibaba/DataX · GitHub
DataX 是阿里云 DataWorks数据集成 的开源版本,在阿里巴巴集团内被广泛使用的离线数据同步工具
/平台。DataX 实现了包括 MySQL、Oracle、OceanBase、SqlServer、Postgre、HDFS、Hive、ADS、HBase、TableStore(OTS)、MaxCompute(ODPS)、Hologres、DRDS, databend 等各种异构数据源之间高效的数据同步功能。
Datax数据处理流程
Datax的使用说明
Datax在使用是主要编写json文件,在json中定义read如何读取 write如何写入
格式: github中可以看到
{
"job": {
"setting": {
"speed": {
"channel": 3
},
"errorLimit": {
"record": 0,
"percentage": 0.02
}
},
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "root",
"password": "123456",
"column": [
"id",
"name"
],
"splitPk": "db_id",
"connection": [
{
"table": [
"table"
],
"jdbcUrl": [
"jdbc:mysql://127.0.0.1:3306/database"
]
}
]
}
},
"writer": {
"name": "streamwriter",
"parameter": {
"print":true
}
}
}
]
}
}
例子:
-- 在mysql中创建库表
create database itcast charset=utf8;
use itcast;
create table student(
id int,
name varchar(20),
age int,
gender varchar(20)
);
insert into student values(1,'张三',20,'男'),
(2,'李四',21,'男'),
(3,'王五',19,'男'),
(4,'赵六',22,'男');
编写datax的json文件:
{
"job": {
"setting": {
"speed": {
"channel": 3
},
"errorLimit": {
"record": 0,
"percentage": 0.02
}
},
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "root",
"password": "123456",
"column": [
"id",
"name",
"age",
"gender"
],
"splitPk": "id",
"connection": [
{
"table": [
"student"
],
"jdbcUrl": [
"jdbc:mysql://192.168.88.80:3306/itcast"
]
}
]
}
},
"writer": {
"name": "streamwriter",
"parameter": {
"print":true
}
}
}
]
}
}
Mysql 数据导入HIVE:
{
"job": {
"setting": {
"speed": {
"channel":1
}
},
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "root", -----用户名字以及密码
"password": "123456",
"column": [ ------------------自己的字段
"id",
"name",
"age",
"gender"
],
"splitPk": "id", ----根据什么字段分割
"connection": [
{
"table": [
"student"
],
"jdbcUrl": [
"jdbc:mysql://192.168.88.80:3306/itcast"
]
}
]
}
},
"writer": {
"name": "hdfswriter",
"parameter": {
"defaultFS": "自己的网址IP",
"fileType": "text",
"path": "自己的路径",
"fileName": "表名",
"column": [
{
"name": "自己表中的字段",
"type": "字段类型"
},
{
"name": "自己表中的字段",
"type": "字段类型"
},
{
"name": "自己表中的字段",
"type": "字段类型"
},
{
"name": "自己表中的字段",
"type": "字段类型"
}
],
"writeMode": "append",
"fieldDelimiter": "," ------------分隔符
}
}
}
]
}
}
使用Datax-Web
如果不想通过finashell进行也可以使用datax-Web
缺点: 不稳定 私人开发的
自己可以去搜一下 不太建议 比较不稳定