Datax系列(二)Mysql和SqlServer同步

参考地址:

https://github.com/alibaba/DataX

一、Mysql同步Mysql

writeMode的类型

  • insert(当主键/唯一性索引冲突时会写不进去冲突的行)
  • replace: 没有遇到主键/唯一性索引冲突时,与 insert into 行为一致,冲突时会用新行替换原有行所有字段
  • update:存在则更新

1.1 准备同步文件

{
    "job": {
        "content": [
            {
                "reader": {
                    "name": "mysqlreader", 
                    "parameter": {
                        "column": ["id","user_name","user_password"], 
                        "connection": [
                            {
                                "jdbcUrl": ["jdbc:mysql://192.168.8.25:3306/dolphinscheduler?useUnicode=true&characterEncoding=utf8"], 
                                "table": ["t_ds_user"]
                            }
                        ], 
                        "password": "root", 
                        "username": "root", 
                        "where": ""
                    }
                }, 
                "writer": {
                    "name": "mysqlwriter", 
                    "parameter": {
                        "column": ["id","user_name","user_password"], 
                        "connection": [
                            {
                                "jdbcUrl": "jdbc:mysql://192.168.8.21:3310/test?useUnicode=true&useSSL=false&characterEncoding=utf8&", 
                                "table": ["ds_user"]
                            }
                        ], 
                        "password": "123456", 
                        "username": "root", 
                        "writeMode": "insert"
                    }
                }
            }
        ], 
        "setting": {
            "speed": {
                "channel": "1"
            }
        }
    }
}

1.2 执行同步

[root@rancher datax]# python ./bin/datax.py ./job/mysql2mysql.json 

二、SqlServer同步Mysql

2.1 准备sqlserver2mysql的json

{
    "job": {
        "content": [
            {
                "reader": {
                    "name": "sqlserverreader", 
                    "parameter": {
                        "connection": [
                            {
                                "jdbcUrl": ["jdbc:sqlserver://Ip:1433;DatabaseName=ecology"], 
                                "table": ["HrmResource"]
                            }
                        ], 
			"column": [
                            "id","loginid","lastname"
                        ],
                        "password": "ganiOA2017", 
                        "username": "sa"
                    }
                }, 
                "writer": {
                    "name": "mysqlwriter", 
                    "parameter": {
                        "column": ["id","loginid","lastname"], 
                        "connection": [
                            {
                                "jdbcUrl": "jdbc:mysql://192.168.8.21:3310/test?useUnicode=true&useSSL=false&characterEncoding=utf8", 
                                "table": ["company_user"]
                            }
                        ], 
                        "password": "123456", 
                        "username": "root", 
                        "writeMode": "replace"
                    }
                }
            }
        ], 
        "setting": {
            "speed": {
                "channel": "10"
            }
        }
    }
}

2.2 执行

[root@rancher datax]# python ./bin/datax.py ./job/sqlserver2mysql.json