datax数据迁移之从oracle往Mysql迁移

Posted 雅冰石

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了datax数据迁移之从oracle往Mysql迁移相关的知识,希望对你有一定的参考价值。

一 实验环境

二 实验步骤

2.1 安装依赖的组件

需要确保已安装以下组件。

JDK(1.8以上,推荐1.8)

Python(推荐Python2.6.X)

Apache Maven 3.X(Compile DataX)

2.1.1 安装jdk

可参考linux下下载安装jdk_雅冰石的专栏-CSDN博客

2.1.2 安装python

Linux操作系统一般自带python,无须手动安装。

检查是否已安装python:

[root@Centos7-Mode-V8 ~]# python -V

Python 2.7.5

2.1.3 安装maven

maven下载地址:Maven – Download Apache Maven

tar -xvf apache-maven-3.8.4-bin.tar.gz

mv apache-maven-3.8.4 /usr/local/maven

vi /etc/profile

添加:

M2_HOME=/usr/local/maven

export PATH=$M2_HOME/bin:/u01/mysql/bin:$PATH

#使修改生效

source /etc/profile

#验证maven是否安装成功

[root@Centos7-Mode-V8 opt]# mvn -v

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)

Maven home: /usr/local/maven

Java version: 1.8.0_231, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_231-amd64/jre

Default locale: en_US, platform encoding: UTF-8

OS name: "linux", version: "3.10.0-957.21.3.el7.x86_64", arch: "amd64", family: "unix"

2.2 安装datax

datax下载地址:http://datax-opensource.oss-cn-hangzhou.aliyuncs.com/datax.tar.gz

tar -xvf datax.tar.gz

rm -rf /opt/datax/plugin/*/._*

/*

如果不删除这些文件,后面迁移数据时会报错:

您提供的配置文件[/opt/datax/plugin/reader/._drdsreader/plugin.json]不存在. 请检查您的配置文件

*/

2.3 迁移数据

要确保迁移的表在目标端已存在。

2.3.1 写迁移脚本

cd datax/job

vi Oracle_to_Mariadb.json

添加:



    "job": 

        "setting": 

             "speed": 

                "byte":1048576,

                "channel":"4"

            

        ,

        "content": [

            

                "reader": 

                    "name": "oraclereader",

                    "parameter": 

                        "username":"sys as sysdba",

                        "password":"密码",

            "where": "",

             "connection": [

                            

                                "querySql": [

                                    "select * from dba_objects"

                                ],

                                "jdbcUrl": ["jdbc:oracle:thin:@192.168.144.207:1521:orcl"]

                            

                        ]

                    

                ,

                "writer": 

                    "name": "mysqlwriter",

                    "parameter": 

            "writeMode": "insert",

            "username": "root",

                        "password": "密码",

                        "column": [

                    "OWNER",

                    "OBJECT_NAME",

                    "SUBOBJECT_NAME",

                    "OBJECT_ID",

                    "DATA_OBJECT_ID",

                    "OBJECT_TYPE",

                    "CREATED",

                    "LAST_DDL_TIME",

                    "TIMESTAMP",

                    "STATUS",

                    "TEMPORARY",

                    "GENERATED",

                    "SECONDARY",

                    "NAMESPACE",

                    "EDITION_NAME"

                        ],

                        "connection": [

                            

                                "jdbcUrl": "jdbc:mysql://192.168.144.252:3306/baidd?useUnicode=true&characterEncoding=utf8",

                                "table": ["dba_objects"]

                            

                        ]

                    

                

            

        ]

    

/*

注意:

① 脚本中需要指定具体的字段名。

② select语句后不要加分号,否则会报错:java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

*/

2.3.2 迁移数据

python ../bin/datax.py Oracle_to_Mariadb.json

确保输出没有错误,且显示如下:

 2.3.3 验证

比对下目标端的数据量和源端是否一致。

select count(*) from baidd.dba_objects;

--实验发现datax不会覆盖目标端的数据,只会追增数据。

本篇文章参考了:

通过DataX从Oracle同步数据到MySQL-安装配置过程 - 小年青。 - 博客园

以上是关于datax数据迁移之从oracle往Mysql迁移的主要内容,如果未能解决你的问题,请参考以下文章

数据库迁移之从oracle 到 MySQL最简单的方法

数据库迁移之从oracle 到 MySQL最简单的方法

怎么将数据库从Oracle迁移到SQL Server,或从Oracle迁移到MySQL

DataX 同步mysql到clickhouse

oracle迁移到mysql注意事项

oracle数据迁移到mysql中去,数据类型不一致