您现在的位置是:首页 >技术教程 >DataX-在Windows上实现postgresql同步数据到mysql网站首页技术教程

DataX-在Windows上实现postgresql同步数据到mysql

霸道流氓气质 2023-06-19 16:00:02
简介DataX-在Windows上实现postgresql同步数据到mysql

场景

DataX-阿里开源离线同步工具在Windows上实现Sqlserver到Mysql全量同步和增量同步:

DataX-阿里开源离线同步工具在Windows上实现Sqlserver到Mysql全量同步和增量同步_霸道流氓气质的博客-CSDN博客

在上面实现sqlserver到mysql的数据同步之后,如果要实现postgresql到mysql数据同步流程一样。

以PostGis中的OGC元数据表中的保存坐标系统信息的spatial_ref_sys表为例。

 

在mysql中新建同样结构的表,将postgresql中这个表的数据同步到mysql的表中。

注:

博客:
霸道流氓气质的博客_CSDN博客-C#,架构之路,SpringBoot领域博主

实现

1、获取postgresqlreader到mysqlwriter的模板

python datax.py -r postgresqlreader -w mysqlwriter

 

2、复制json模板到postgresql2mysql.json文件

参考配置项说明文档

https://github.com/alibaba/DataX/blob/master/postgresqlreader/doc/postgresqlreader.md

DataX/mysqlwriter.md at master · alibaba/DataX · GitHub

修改json文件为自己对应的url和列等信息。

{
    "job": {
        "content": [
            {
                "reader": {
                    "name": "postgresqlreader",
                    "parameter": {
                        "connection": [
                            {
                                "jdbcUrl": [
        "jdbc:postgresql://127.0.0.1:5432/数据库名"
        ],
                                "table": [
        "spatial_ref_sys"
        ]
                            }
                        ],
                        "password": "密码",
                        "username": "postgres",
      "column": [
      "srid",
      "auth_name",
      "auth_srid",
      "srtext",
      "proj4text",
      ]
                    }
                },
                "writer": {
                    "name": "mysqlwriter",
                    "parameter": {
                        "column": [
      "srid",
      "auth_name",
      "auth_srid",
      "srtext",
      "proj4text",
      ],
                        "connection": [
                            {
                                "jdbcUrl": "jdbc:mysql://127.0.0.1:3306/数据库名?useUnicode=true&characterEncoding=gbk",
                                "table": [
        "spatial_ref_sys"
        ]
                            }
                        ],
                        "password": "密码",
                        "preSql": [
      "delete from spatial_ref_sys"
      ],
                        "session": [],
                        "username": "root",
                        "writeMode": "insert"
                    }
                }
            }
        ],
        "setting": {
            "speed": {
                "channel": "5"
            }
        }
    }
}

执行同步命令

python datax.py ./postgresql2mysql.json

同步成功

 

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。