• oracle库中数据利用datax工具同步至mysql库


    查看oracle版本

    $sqlplus aaa/aaaa@192.168.1.1/lcfa
    
    SQL*Plus: Release 19.0.0.0.0 - Production on Tue Oct 17 15:56:46 2023
    Version 19.15.0.0.0
    
    Copyright (c) 1982, 2022, Oracle.  All rights reserved.
    
    Last Successful login time: Tue Oct 17 2023 15:56:03 +08:00
    
    Connected to:
    Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
    Version 19.15.0.0.0
    
    SQL> exit
    Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
    Version 19.15.0.0.0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    查看mysql版本

    $mysql -V
    mysql  Ver 14.14 Distrib 5.7.43, for linux-glibc2.12 (x86_64) using  EditLine wrapper
    
    • 1
    • 2

    查看主机版本

    $cat /etc/redhat-release 
    Red Hat Enterprise Linux Server release 7.6 (Maipo)```
    
    • 1
    • 2

    查看主机jdk和python版本

    $ java -version
    openjdk version "1.8.0_181"
    OpenJDK Runtime Environment (build 1.8.0_181-b13)
    OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
    
    $python --version
    Python 2.7.5
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    注意点:
    1、部署datax的主机需要jdk1.8和python2.7.5以上版本,主机、数据库版本没有要求

    2、部署datax的主机需要安装python控件cx_Oracle-7.3.0来登录oracle

    3、部署datax的主机需要和mysql、oracle主机网络是通的且能登录数据库

    4、mysql和oracle库中表的字段必须要统一,josn配置文件中字段要一样

    5、Mysql保留字处理:
    ID,ip,port,desc 等mysql的关键字被认为是保留字,这个不能用在json文件中

    第一步:解压datax

    tar -zxvf datax.tar.gz 
    ls -rlt
    total 810304
    -rw-rw-r--  1 lcims lcims 829749309 Oct 16 14:34 datax.tar.gz
    drwxr-x--- 14 lcims lcims       236 Oct 16 14:52 datax
    
    • 1
    • 2
    • 3
    • 4
    • 5

    datax目录包含:
    在这里插入图片描述

    bin:程序的执行目录,里面的data.py是控制台执行该程序的启动文件
    log:执行后的日志,每执行一次生成一个日志文件,可以清楚的看到报错信息
    plugin:reader和writer插件,比如reader里的mysqlreader为mysql的读取插件
    3ajob:是自定义的文件夹,写入了要迁移的表信息 
    
    • 1
    • 2
    • 3
    • 4

    3ajob目录下为要迁移表数据的josn文件配置信息:
    python /datax/datax/bin/datax.py -r mysqlreader -w oraclewriter --查看josn格式模板

    ./3ajob/tables_name.josn
    解释:
    {
        "job": {
            "setting": {
                "speed": {
                    "channel": 16    #(这个是多线程,我们是16核cpu,所以用的是16)
                }
            }, 
            "content": [
                {
                    "reader": {
                        "name": "oraclereader", #(oracle的信息配置,从oracle读取)
    
                        "parameter": {
                            "username": "test", #(oracle的用户和密码)
                            "password": "test", #(oracle的用户和密码)
                            "column": [   #(column[]中是oracle表中的字段信息)
                                "aaa",
    "bbb",
    "ccc"
                            ],
    						"where":" 1=1 ",
                            "connection": [
                                {
                                    "table": [
                                        "表名" #(要迁移的表)
                                    ], 
                                    "jdbcUrl": [
                                        "jdbc:oracle:thin:@ip:端口/实例"#(oracle表数据源配置)
                                    ]
                                }
                            ]
                        }
                    }, 
                    "writer": {
                        "name": "mysqlwriter", #(mysql写入配置)
                        "parameter": {
                            "writeMode": "update", #(mysql写入配置)
                            "username": "test", 
                            "password": "test", 
                            "column": [ #(mysql字段)
                                    "aaa",
    "bbb",
    "ccc"
                            ], 
                            "session": [
                                "set session sql_mode='ANSI'"
                            ], 
                            "preSql": [
                                "select 1 from 表名"
                            ], 
                            "connection": [#(mysql链接信息)
                                {
                                    "jdbcUrl": "jdbc:mysql://ip:端口/实例?useUnicode=true&characterEncoding=utf8", 
                                    "table": [
                                        "表名"
                                    ]
                                }
                            ]
                        }
                    }
                }
            ]
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66

    配置完成进入bin目录执行脚本,查看日志

    进入bin目录
    cd  ./datax/bin
    执行命令:nohup python ./datax.py /路径/脚本名 &
    例:
    $  nohup python ./datax.py ../3ajob/aaa.json &
    查看日志:tail -100f nohup.out 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在这里插入图片描述

    数据同步完成,即可查看mysql中的数据

  • 相关阅读:
    Vue:搭建前端项目
    Tomcat以及UDP
    操作系统——处理机调度、进程调度、调度算法的评价指标
    确保软件供应链安全,不容忽略的三大步骤
    5. Layui数据表格的快速使用
    一款好用的问卷调查工具要必备哪些功能特点?
    常用的国内镜像源
    一文解决Cellphonedb单细胞互作分析及可视化作图(2)
    网络运维管理从基础到实战-自用笔记(1)构建综合园区网、接入互联网
    Redis过期策略以及内存淘汰机制
  • 原文地址:https://blog.csdn.net/weixin_44369870/article/details/133886237