新创建的测试库(mysql),需要使用oracle库中几张表的数据,要求使用goldengate来完成oracle数据到mysql数据库的同步。
此同步同oralce到oracle的同步并无太大区别,同样源库(oracle)一个抽取进程和一个传递进程,目标库(mysql)一个应用进程;初始化也可以使用goldengate完成,也可以使用别的方式(此次使用navicat工具完成),下面是具体过程:
源:Redhat 6.4+oracle10.2+goldengate12
目标:Centos 6.6+mysql5.6+goldengate12
1、初始化mysql
1)创建数据库
mysql> create database gmdc;
2)将oracle已有的数据导入到mysql中,可使用navicat(链接: http://blog.csdn.net/u010587433/article/details/49101737)
2、源库
1)开启附加日志
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
---------------
NO
SQL> alter database add supplemental log data;
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
---------------
YES
2)开户归档(已经是归档模式,省略)
SQL> alter system set log_archive_dest_1='location=/u01/archivelog';
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/arch
SQL> alter database open;
3)开启强制写日志(可以不开启,最好开启)
SQL> select force_logging from v$database;
FOR
------
NO
SQL> alter database force logging;
SQL> select force_logging from v$database;
FOR
------
YES
4)创建用户并授权
SQL> create tablespace ggtbs datafile '/u01/oradata/db1/ggtbs01.dbf' size 200m autoextend on;
SQL> create user ogg identified by ogg default tablespace ggtbs quota unlimited on ggtbs;
SQL> grant connect,resource,create session,alter session to ogg;
SQL> grant select any dictionary,select any table, alter any table, create any table,flashback any table to ogg;
SQL> grant execute on dbms_flashback to ogg;
5)创建目录解压
mkdir /home/oracle/goldengate
chown oracle:oinstall /home/oracle/goldengate
cd /home/oracle/goldengate
unzip ggs_121210_Linux_x64_MySQL_64bit.zip
tar xvf ggs_Linux_x64_MySQL_64bit.tar
./ggsci
GGSCI (pos300-db01) 1> create subdirs
Creating subdirectories under current directory /home/mysql
Parameter files /goldengate/dirprm: created
Report files /goldengate/dirrpt: created
Checkpoint files /goldengate/dirchk: created
Process status files /goldengate/dirpcs: created
SQL script files /goldengate/dirsql: created
Database definitions files /goldengate/dirdef: created
Extract data files /goldengate/dirdat: created
Temporary files /goldengate/dirtmp: created
Stdout files /goldengate/dirout: created
6)为表级添加附加日志
GGSCI (pos300-db01) 2> dblogin userid ogg
Password:
Successfully logged into database.
GGSCI (pos300-db01) 3> add trandata gmdc.*
7)创建管理进程,并启动
./ggsci
GGSCI (pos300-db01) 1> edit params mgr
port 7809
autorestart er *, retries 5, waitminutes 3
purgeoldextracts /home/oracle/goldengate/dirdat/*,usecheckpoints, minkeepdays 2
GGSCI (pos300-db01) 2> start mgr
Manager started.
GGSCI (pos300-db01) 3> info mgr
Manager is running (IP port pos300-db01.7809, Process ID 2897).
8)extract进程,并启动
GGSCI (pos300-db01) 2> edit params DCE1
extract dce1
setenv (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")
THREADOPTIONS MAXCOMMITPROPAGATIONDELAY 90000
userid ogg, password ogg
exttrail /home/oracle/goldengate/dirdat/e1
discardfile /home/oracle/goldengate/dirrpt/dce1.dsc,append
numfiles 3000
dynamicresolution
TABLE gmdc.cksp;
TABLE gmdc.dgdcsp;
TABLE gmdc.dcckcl;
TABLE gmdc.dcclz;
TABLE gmdc.ck;
GGSCI (pos300-db01) 3> add extract dce1,tranlog,begin now
GGSCI (pos300-db01) 4> add exttrail /home/oracle/goldengate/dirdat/e1,extract dce1,megabytes 5
GGSCI (pos300-db01) 5> start DCE1
9)pump进程,并启动
>GGSCI (pos300-db01) 6> edit params DCP1
extract dcp1
passthru
setenv (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")
userid ogg, password ogg
rmthost 192.168.7.221,mgrport 7809,compress
rmttrail /home/mysql/goldengate/dirdat/p1
dynamicresolution
numfiles 3000
TABLE gmdc.cksp;
TABLE gmdc.dgdcsp;
TABLE gmdc.dcckcl;
TABLE gmdc.dcclz;
TABLE gmdc.ck;
GGSCI (pos300-db01) 7> add extract dcp1,exttrailsource /home/goldengate/dirdat/me
GGSCI (pos300-db01) 8> add rmttrail /home/mysql/golengate/dirdat/p1,extract dcp1,megabytes
GGSCI (pos300-db01) 9> start DCP1
10)创建要同步的表的定
#创建参数文件
GGSCI (pos300-db01) 10> edit param defgen
defsfile ./dirdef/gmdc.def
userid ogg, password ogg
table gmdc.*;
#生成表定义文件
./defgen paramfile ./dirprm/defgen.prm
#传至目标库目录
scp /home/oracle/goldengate/dirdef/gmdc.def 192.168.7.221:/home/mysql/goldengate/dirprm/
3、目标库
目标库为Mysql, 同oracle与oracle之间的同步略有区别
1)创建用户
mysql> GRANT ALL PRIVILEGES ON `gmdc`.* TO 'ogg'@'%' IDENTIFIED BY ‘ogg'
2)创建目录
cd /home/mysql
mkdir goldengate/
chown mysql:mysql ./goldengate
unzip ggs_121210_Linux_x64_MySQL_64bit.zip
tar xvf ggs_Linux_x64_MySQL_64bit.tar
./ggsci
GGSCI (zoop300) 1> create subdirs
Creating subdirectories under current directory /home/mysql
Parameter files /goldengate/dirprm: created
Report files /goldengate/dirrpt: created
Checkpoint files /goldengate/dirchk: created
Process status files /goldengate/dirpcs: created
SQL script files /goldengate/dirsql: created
Database definitions files /goldengate/dirdef: created
Extract data files /goldengate/dirdat: created
Temporary files /goldengate/dirtmp: created
Stdout files /goldengate/dirout: created
3)配置管理进程
GGSCI (zoop300) 3> edit params mgr
port 7809
dynamicportlist 7840-7939
autorestart er *, retries 5, waitminutes 3
purgeoldextracts /home/goldengate/dirdat/*,usecheckpoints, minkeepdays 2
GGSCI (zoop300) 4> start mgr
Manager started.
GGSCI (zoop300) 3> info mgr
Manager is running (IP port zoop300.7809, Process ID 2897).
4)配置检查点及全局
GGSCI (zoop300) 4> dblogin sourcedb [email protected]:3306 userid ogg password ogg
GGSCI (zoop300) 5> add checkpointtable gmdc.checkpoint_table
GGSCI (zoop300) 6> edit params ./GLOBALS
checkpointtable gmdc.checkpoint_table
5)配置replicat进程
GGSCI (zoop300) 7> edit params dcr1
replicat dcr1
targetdb [email protected]:3306 userid ogg password ogg
handlecollisions
sourcedefs /home/mysql/goldengate/dirprm/gmdc.def
discardfile /home/mysql/goldengate/dirrpt/dcr1.dsc,purge
map gmdc.ck,target gmdc.CK;
map gmdc.cksp,target gmdc.CKSP;
map gmdc.dcclz,target gmdc.DCCLZ;
map gmdc.dcckcl,target gmdc.DCCKCL;
map gmdc.dgdcsp,target gmdc.DGDCSP;
GGSCI (zoop300) 8> add replicat dcr1,exttrail /home/mysql/goldengate/dirdat/p1,checkpointtable gmdc.checkpoint_table
GGSCI (zoop300) 9> start dcr1
4、测试数据同步
说明:注意mysql中表名区分大小写