cd F:\datax
python bin/datax.py -r mysqlreader -w mysqlwriter
模板如下:
DataX (DATAX-OPENSOURCE-3.0), From Alibaba !
Copyright (C) 2010-2017, Alibaba Group. All Rights Reserved.
Please refer to the mysqlreader document:
https://github.com/alibaba/DataX/blob/master/mysqlreader/doc/mysqlreader.md
Please refer to the mysqlwriter document:
https://github.com/alibaba/DataX/blob/master/mysqlwriter/doc/mysqlwriter.md
Please save the following configuration as a json file and use
python {DATAX_HOME}/bin/datax.py {JSON_FILE_NAME}.json
to run the job.
{
"job": {
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"column": [],
"connection": [
{
"jdbcUrl": [],
"table": []
}
],
"password": "",
"username": "",
"where": ""
}
},
"writer": {
"name": "mysqlwriter",
"parameter": {
"column": [],
"connection": [
{
"jdbcUrl": "",
"table": []
}
],
"password": "",
"preSql": [],
"session": [],
"username": "",
"writeMode": ""
}
}
}
],
"setting": {
"speed": {
"channel": ""
}
}
}
}
创建配置文件
具体配置项目说明参见官网 https://github.com/alibaba/DataX
将上面配置模板copy下来放在配置json文件中后,进行以下改写:
{
"job": {
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"column": [这里需要所有列的话可以直接填"*",否则需要自己填写每个需要的列],
"connection": [
{
"jdbcUrl": [
"jdbc:mysql://ip:端口/数据库名?userSSL=false&serverTimezone=UTC"
],
"table": ["表名"]
}
],
"password": "密码",
"username": "用户名",
"where": "查询条件,没有可为空,例子:date_time <= DATE_FORMAT($(date_time),'%Y-%m-%d')"
}
},
"writer": {
"name": "mysqlwriter",
"parameter": {
"column": [
"id",
"name"
],
"connection": [
{
"jdbcUrl": "jdbc:mysql://127.0.0.1:3306/test?userSSL=false&serverTimezone=UTC", (这里数据库版本为8.0以上的,数据库名后面必须加上两个参数,不然会报错的)
"table": [
"test_db"
]
}
],
"password": "root",
"preSql": [],
"session": [],
"username": "root",
"writeMode": "insert"
}
}
}
],
"setting": {
"speed": {
"channel": "1"
}
}
}
}
python bin/datax.py job/mysql2mysql.json
校验数据库是否可以正常连接,如正常进入下一步
1、确认mysql数据库版本(我这里的mysql版本为8.0.18)
2、查询相关问题后得知,datax3.0的mysql驱动包是不支持mysql8.0以上版本的,所以我这里将datax的mysql驱动包进行更新替换
python bin/datax.py job/mysql2mysql.json
报错信息显示jdk版本不一致,所以我们打开终端输入一下命令:
java -version
这里我们可以看到jdk版本为1.7的,但是环境变量和本地的包都是1.8的,那么问题就知道了,win10系统中是有可能出现这样的问题的,如果是自己的电脑可以参考这个文章:https://www.cnblogs.com/zhangzhonghui/p/10678028.html
如果自己没有权限的话,那就好办了,让系统管理员安排一下,嘿嘿~
成功解决上述问题后
python bin/datax.py job/mysql2mysql.json
Nice!成功!
最后,datax中的where条件是可以使用动态传参的形式进行运行的,也可以实现多表同步实现,详细介绍:http://www.lhtry.net/blog/detail/29