DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具/平台,实现包括 MySQL、Oracle、SqlServer、Postgre、HDFS、Hive、ADS、HBase、TableStore(OTS)、MaxCompute(ODPS)、DRDS 等各种异构数据源之间高效的数据同步功能。
1:Java 1.8.0_231
2.Python 3.6.5
3.MySQL:5.5.53
3.Datax:http://datax-opensource.oss-cn-hangzhou.aliyuncs.com/datax.tar.gz(约800M)
下载地址:https://github.com/alibaba/DataX页面Download DataX下载地址
MySQL
建库:sourcedb
建表:t_user_info
CREATE TABLE `t_user_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`content` text,
`createdate` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
导数:
INSERT INTO `sourcedb`.`t_user_info` (`id`, `name`, `content`, `createdate`) VALUES ('1', 'linux重启mysql的命令', 'linux重启mysql的命令', '2020-04-19 21:18:58');
INSERT INTO `sourcedb`.`t_user_info` (`id`, `name`, `content`, `createdate`) VALUES ('2', 'jQuery给input绑定回车事件', 'jQuery给input绑定回车事件', '2020-04-20 21:19:14');
INSERT INTO `sourcedb`.`t_user_info` (`id`, `name`, `content`, `createdate`) VALUES ('3', 'Web开发Session超时设置', 'Web开发Session超时设置', '2020-04-21 21:19:19');
建库:targetdb
建表:t_user_info
CREATE TABLE `t_user_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`content` text,
`createdate` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
如要支持Python需要修改DataX默认py文件
下载:https://github.com/WeiYe-Jing/datax-web/tree/master/doc/datax-web/datax-python3
替换datax/bin/datax.py,datax/bindxprof.py,datax/binperftrace.py
{
"job": {
"setting": {
"speed": {
"channel": 1
}
},
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "root",
"password": "111111",
"column": [ "id", "name","content" ,"createdate"],
"splitPk": "id",
"connection": [
{
"table": [
"t_user_info"
],
"jdbcUrl": [
"jdbc:mysql://127.0.0.1:3306/sourcedb"
]
}
]
}
},
"writer": {
"name": "mysqlwriter",
"parameter": {
"writeMode": "insert",
"username": "root",
"password": "111111",
"column": [ "id", "name","content","createdate"],
"session": [
"set session sql_mode='ANSI'"
],
"preSql": [
"delete from t_user_info"
],
"connection": [
{
"jdbcUrl": "jdbc:mysql://127.0.0.1:3306/targetdb",
"table": [
"config"
]
}
]
}
}
}
]
}
}
cd datax
python .\bin\datax.py .\task\mysql-2-mysql.json
bytes | All Task WaitWriterTime 0.000s | All Task WaitReaderTime 0.000s | Percentage 100.00%
use targetdb;
select * from t_user_info;
sourcedb中t_user_info数据已经复制到targetdb的t_user_info表中