用OGG将Oracle的数据迁移至MySQL
来源:长沙北大青鸟|发布时间:2017-03-22|浏览量:
如何实现把Oracle的数据迁移到MySQL上,因为还涉及了几个表,不妨先使用spool把Oracle的数据导成txt文件,接下来再load 进去MySQL。但当面对数据量大、字段多的情况时,就会出现只能导进一部分数据的情况,而没法得到较好的解决。因而尝试用golden gate来解决,golden gate安装便捷只要解压便可以了,主要便是几个进程的配置。
整体迁移的思路以及注意事项:
首先在oracle端和mysql端安装上OGG,安装很简单,然后在oracle源端和目标端配置好mgr(端口需要一致),然后在源端配置上抓取进程,在目标端配置上replicate进程(只运行一次即可),然后在源端使用DEFGEN命令做映射文件,并把文件传到mysql端相应目录下。启动源端的抓取进程即可实现数据库初始化,也就完成了数据迁移。
注意事项和相关报错:
1,oracle到mysql的ogg属于异构的ogg, 需要借助DEFGEN命令生成一个映射文件,也就是两个表的映射关系,并把文件放到目标端相应位置下。否则会报错WARNING OGG-01194 EXTRACT task RINIG1 abended : Could not find definition for INFOSERVICE.T_MEMBER_INFO_SUM
2,在源端配置抓取进程,需要注意的是:初始化数据库过程需要一个的抓取进程,之后保持数据同步也需要一个抓取进程,这两个抓取进程是有区别的,然后目的端也需要两个replicate进程,一个用来初始化数据库,一个用来实时同步数据 。
3,注意oracle字段默认是区分大小写的,但是mysql默认是不区分的。如下:
mysql> select login_id from T_MEMBER_INFO where login_id = 'SHFRONT';
+----------+
| login_id |
+----------+
| shfront |
| SHFRONT |
+----------+
2 rows in set (0.81 sec)
需要这样修改,让mysql对大小写敏感。
mysql> alter table T_MEMBER_INFO modify login_id varchar(100) binary;
mysql> select login_id from T_MEMBER_INFO where login_id = 'SHFRONT';
+----------+
| login_id |
+----------+
| SHFRONT |
+----------+
1 row in set (0.78 sec)
如果mysql的主键是login_id,那么可能会遇到下面这个报错,主键冲突,真正的原因是:mysql字段值默认是不区分大小写
报错:WARNING OGG-01004 Aborted grouped transaction on 'liuwenhe.T_MEMBER_INFO_SUM', Database error 1062 ([SQL error 1062]Duplicate entry 'shandongchaoyue' for key 'PRIMARY'
从oracle转到MySQL的OGG,在使用mysql过程中,会遇到很多不同于oracle的问题,初始化数据的时候总是报主键冲突,但是这些数据都是从同样表结构的oracle数据库中导出来的,当然主键也是一样的。
查看了一下数据文件,发现存在很多数据只是大小写不一样,如’goolen,‘GOOLEN’,‘Goolen’这样的数据,
其实MySQL中,字段值默认是不区分大小写的,也就是说插入值‘abc’和'ABC‘是等价的,
下面展示具体的配置:
源端oracle 抓取进程配置:
[oracle@master2 ggs]$ cd /u01/OGG_linux/ggs
[oracle@master2 ggs]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
1,GGSCI (master2) 1> create subdirs
Creating subdirectories under current directory /u01/OGG_linux/ggs
Parameter files /u01/OGG_linux/ggs/dirprm: already exists
Report files /u01/OGG_linux/ggs/dirrpt: created
Checkpoint files /u01/OGG_linux/ggs/dirchk: created
Process status files /u01/OGG_linux/ggs/dirpcs: created
SQL script files /u01/OGG_linux/ggs/dirsql: created
Database definitions files /u01/OGG_linux/ggs/dirdef: created
Extract data files /u01/OGG_linux/ggs/dirdat: created
Temporary files /u01/OGG_linux/ggs/dirtmp: created
Stdout files /u01/OGG_linux/ggs/dirout: created,
2,登录数据库
GGSCI (master2) 3> dblogin userid ogg,password ogg
Successfully logged into database.
3,添加需要同步的用户到ogg
开启scott用户下所有表的附加日志
GGSCI (WebServer) 3> add trandata infoservice.*
2013-03-08 11:02:33 WARNING OGG-00869 No unique key is defined for table 'BONUS'.
All viable columns will be used to represent the key, but may not guarantee
uniqueness. KEYCOLS may be used to
define the key.
Logging of supplemental redo data enabled
for table SCOTT.BONUS.
Logging of supplemental redo data enabled
for table SCOTT.DEPT.
Logging of supplemental redo data enabled
for table SCOTT.EMP.
2013-03-08 11:02:34 WARNING OGG-00869 No unique key is defined for table
'SALGRADE'. All viable columns will be used to represent the key, but may not
guarantee uniqueness. KEYCOLS may be
used to define the key.
Logging of supplemental redo data enabled
for table SCOTT.SALGRADE.
4,GGSCI (WebServer) 4> info trandata scott.*
Logging of supplemental redo log data is
enabled for table SCOTT.BONUS.
Columns supplementally logged for table
SCOTT.BONUS: ENAME, JOB, SAL, COMM.
Logging of supplemental redo log data is
enabled for table SCOTT.DEPT.
Columns supplementally logged for table
SCOTT.DEPT: DEPTNO.
Logging of supplemental redo log data is
enabled for table SCOTT.EMP.
Columns supplementally logged for table
SCOTT.EMP: EMPNO.
Logging of supplemental redo log data is
enabled for table SCOTT.SALGRADE.
Columns supplementally logged for table
SCOTT.SALGRADE: GRADE, LOSAL, HISAL.
3,GGSCI (master2) 3>edit params mgr
PORT 7839
4,GGSCI (master2) 3> start mgr
5,GGSCI (master2) 3>info mgr
Manager is running (IP port
WebServer.7839).
1.抓取进程
GGSCI (oracle3) 10>add extract ext_1,sourceistable ####sourceistable代表直接从表中读取数据
GGSCI (oracle3) 10> view params ext_1
extract ext_1
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
userid goldengate@cbl , password ogg123456
rmthost 192.168.0.12,mgrport 7839
rmttask replicat,group rinig1
table INFOSERVICE.T_MEMBER_INFO;
2.DEFGEN命令生成的映射文件。
1)创建DEFGEN工具的参数文件;
GGSCI (oracle3) 3> view params defgen
defsfile ./dirdef/source.def, purge
userid ogg@rman_cbl1 , password ogg
TABLE INFOSERVICE.T_PUBLISH_INFO;
TABLE INFOSERVICE.T_PUBLISH_ZBXX;
TABLE INFOSERVICE.T_MEMBER_INFO;
TABLE INFOSERVICE.T_MEMBER_INFO_FUBIAO1;
TABLE INFOSERVICE.T_MEMBER_INFO_SUM;
TABLE INFOSERVICE.T_MEMBER_MY;
TABLE INFOSERVICE.T_MEMBER_MY_INFO;
TABLE INFOSERVICE.T_PUBLISH_INFO_SUM_TONGJI;
TABLE INFOSERVICE.USER_REGIST_LS_FAIL;
TABLE INFOSERVICE.USER_REGIST_LS;
2))运行DEFGEN工具生成数据定义文件
进入GGSCI安装目录下,命令行执行:
[oracle@oracle3 ogg]$./defgen paramfile dirprm/defgen.prm
3)把生成的文件 scp到目标端相应文件下:
[oracle@oracle3 ogg]scp /home/oracle/ogg/dirdef/source.def root@192.168.0.12:/files/ogg/dirdef/source.def
目标端:replicate 配置:
GGSCI (db2) 1> add replicat rinig1,specialrun //specialrun代表只运行一次
注意下面的target liuwenhe.T_MEMBER_INFO
GGSCI (server02) 12> view params rinig1
replicat rinig1
sourcecharset ZHS16GBK
setenv (NLS_LANG=AMERICAN_AMERICA.zhs16gbk)
sourcedefs ./dirdef/source.def
sourcedb infoservice,userid ogg,password ogg
discardfile ./dirrpt/rinig1.dsc,purge
map infoservice.T_MEMBER_INFO, target liuwenhe.T_MEMBER_INFO REPERROR (1403, discard);
最后打开源端的抓取进程即可
GGSCI (oracle3) 3>start ext_1
GGSCI (oracle3) 3> view report ext_1 ###查看输出结果
最后可以看日志:
ogg错误日志
[root@server02 dirdef]# find / -name ggserr.log
[root@server02 dirdef]#tail -f /files/ogg/ggserr.log
总结:
oracle到mysql的ogg需要借助defgen命令生成的映射文件,并把文件传到目标端相应位置下,才能完成数据库初始化,用于初始化的replicate进程,只会运行一次。注意字符集问题,就是源端的抓取进程配置的字符集和目标端replicate配置的字符集必须是一样的,否则可能会导致只导进去一部分数据。
下一篇:如何以windows集成方式连接sql Server?
扫码关注微信公众号了解更多详情
跟技术大咖,专业导师一起交流学习
- 推荐阅读