概述
业务中经常会用到数据全量同步和增量同步,用sqlDump只能全量同步,而且数据量大的时候很慢。
阿里的datax目前是一款不错的同步工具
环境要求:
jdk:1.8+
python:2.7
maven:3.0+
3.0
的python
跑不起来
ps
:开源版的datax
的mysql
驱动还是用的5.1.x
的,如果用的mysql
已经是高版本了,需要换下驱动.换驱动的时候记得read
和writer
都要换一下。
demo
直接跟着datax
的quick start
开始敲就完事
https://github.com/alibaba/DataX/blob/master/userGuid.md
我是直接下载的工具包,然后直接查看read
和write
模板,直接按照模板copy
一个.json
的文件
python datax.py -r {YOUR_READER} -w {YOUR_WRITER}
文件deom
如下
{
"job": {
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "xxx",
"password": "xxx",
"where": "",
"connection": [
{
"querySql": [
"select * from sys_oper_log;"
],
"jdbcUrl": [
"jdbc:mysql://127.0.0.1:33306/ruoyi_5?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true"
]
}
]
}
},
"writer": {
"name": "mysqlwriter",
"parameter": {
"column": ["*"],
"connection": [
{
"jdbcUrl": "jdbc:mysql://127.0.0.1:33306/datax_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true",
"table": ["sys_oper_log"]
}
],
"password": "xxx",
"preSql": [
],
"session": [
"set session sql_mode='ANSI'"
],
"username": "xxx",
"writeMode": "insert"
}
}
}
],
"setting": {
"speed": {
"channel": "5"
}
}
}
}
直接运行
python2.7 datax.py test.json