oggoracletomysql_借助OGG完成Oracle到MySQL的数据迁移现在有个任务是需要把Oracle的数据迁移到MySQL,因为就涉及到了⼏个表,所以我最先想到了使⽤spool把Oracle的数据导成txt⽂件,然后再load 进去MySQL。⾮常遗憾的是,我的有⼀个表有110个字段,并且有160万的数据,始终就只能倒进⼀部分数据,最后由于时间问题,没有继续尝试,然后打算⽤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.loglinux安装oracle 11g
总结:
oracle到mysql的ogg需要借助defgen命令⽣成的映射⽂件,并把⽂件传到⽬标端相应位置下,才能完成数据库初始化,⽤于初始化的replicate进程,只会运⾏⼀次。注意字符集问题,就是源端的抓取进程配置的字符集和⽬标端replicate配置的字符集必须是⼀样的,否则可能会导致只导进去⼀部分数据。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。