oracle异构mysql_配置Oracle GoldenGate异构oracle到mysql同步

最近研究了一下oracle Goldengate异构同步的过程,

真是几天不用手生,敲命令竟然如此生疏。不过还算顺利,经过一番折腾终于好了。

环境描述:

192.0.2.101( Oracle ) —>192.0.2.102 (Mysql )

版本:

操作系统:redhat6.5

Oracle

:  12.1.0.2.0

Mysql:     5.6.25

goldgate:

Version 12.2.0.1.1 for oracle

Version 12.2.0.1.1  formysql

测试用户:

在oracle创建2个用户,并创建了2张表,同步到mysqltest数据库下。

Oracle to Mysql

需要注意的地方:

Supported data types for mysql

CHAR

DOUBLE

TINYTEXT

VARCHAR

DATE

MEDIUMTEXT

INT

TIME

LONGTEXT

TINYINT

YEAR

BLOB

SMALL  INT

DATETIME

TINYBLOB

MEDIUM  INT

TIMESTAMP

MEDIUMBLOB

BIG  INT

BINARY

LONGBLOB

DECIMAL

VARBINARY

ENUM

FLOAT

TEXT

BIT(M)

Oracle GoldenGate supports InnoDB storageengine for a source MySQL database

goldengate

对mysql只支持innodb引擎

所以,在创建mysql端的表的时候,要指定表为innodb引擎。但是5.6默认的存储引擎就是InnoDB。

一:Oracle端的基础配置

初始化ogg

/u01/ogg/dbhome

[oracle@host01 dbhome]$ ./ggsci

Oracle GoldenGate Command Interpreter for Oracle

Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO

Linux, x64, 64bit (optimized), Oracle 12c on Dec 12 2015 02:56:48

Operating system character set identified as UTF-8.

Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rightsreserved.

GGSCI (host01.example.com) 1>

GGSCI (host01.example.com) 9> create  subdirs

1.1.

修改oracle数据库的参数

1.2

修改数据库为归档模式

1.3

打开辅助日志

alter database add supplemental log data

1.34

关闭回收站

alter system set recyclebin=off scope=both;

(10g以后可以不关闭)

下面报错以上由于没设参数以及授予权限,

OGG REPLICAT abend:

ERROR   OGG-01820 Could not enable workspace.

ERROR   OGG-01668 PROCESS ABENDING.

通过设置alter system setenable_goldengate_replication=true scope=both ;解决

1.5

创建复制用的用户,并授权

create  tablespaceoggtb  datafile'/u01/app/oracle/oradata/PROD4/oggtb01.dbf' size 1g ;

create  tablespaceoggtb  datafile'/u01/app/oracle/oradata/EMREP/oggtb01.dbf' size 1g ;

create user ogg identifiedby ogg default  tablespace  oggtb;

grant connect,resource toogg;

grant unlimited tablespaceto ogg;

grant execute on utl_fileto ogg;

在ogg的安装目录下登陆sqlplus,使用sys登陆sqlplus,然后执行如下配置

[oracle@local ~]$ sqlplus /nolog

SQL> conn / as sysdba

SQL> @marker_setup.sql

SQL> @ddl_setup.sql;

SQL> @role_setup.sql;

SQL> grant GGS_GGSUSER_ROLE to ogg;

SQL> @ddl_enable.sql;

进入ogg控制台,测试用户是否创建成功

GGSCI (local) 1> dblogin userid ogg

Password: ogg

Successfully logged into database.

由于异构数据库之间不支持ddl复制,mysql也没有Oracle使用的

sequence

,所以数据库上不需要启用DDL

复制支持和

Sequence

复制支持。(上边步骤可以省略)

二:target 端(Mysql)

2.1

配置Mysql参数

Mysql

的引擎很多,但是OGG只支持Innodb 的引擎,所以需要修改mysql的配置文件开启

binary

logging,

/

etc

/

my.conf

文件中添加如下内容

log-bin=/u01/mysql/log/binary-log

log-bin-index=/u01/mysql/log/binary-log.index

binlog_format

=

row

说明:

1

.

设为

row

使得dml语句以

binary

格式记入日志,任何其他日志格式(mixed或

statement

)将引起

extract

进程停止。因为ogg支持InfoDB。

2

.

这里直接将Mysql默认的引擎改成INNODB了,当然也可以在创建表的时候修改。

-

-

重启mysql数据库:

[root@host02 ~]# msyqladmin shutdown

[root@host02 ~]# mysqld_safe &

创建测试数据库test和表 zw,tt

createtable zw(id integer primarykey,name varchar(20));

mysql> create table  tt (id varchar(1));

Query OK, 0 rows affected (0.07 sec)

2.2

修改ogg参数

GGSCI(host02.example.com) 1> dblogin sourcedb test,userid root,password root123

GGSCI(host02.example.com) 1> edit params mgr

port7808

GGSCI(host02.example.com) 2> info all

Program     Status     Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING

三、配置同步source

GGSCI(host01.example.com) 1> add extract extmy3,tranlog,begin now

ADDEXTTRAIL /u01/ogg/dbhome/dirdat/E3, EXTRACT EXTMY3, megabytes 100

GGSCI(host01.example.com) 2> view param extmy3

extractextmy3

useridogg,password ogg

exttrail/u01/ogg/dbhome/dirdat/E3

tabletest.zw;

tablehr.tt;

--fetchoptionsfetchpkupdatecols

GGSCI(host01.example.com) 3>

在source 端添加 datapump进程

GGSCI(host01.example.com) 3> add extract pumpmy3,exttrailsource/u01/ogg/dbhome/dirdat/E3

addrmttrail  /u01/oggmysql/dirdat/R3,extractpumpmy3

GGSCI(host01.example.com) 4> view param pumpmy3

extractpumpmy3

rmthost192.0.2.102,mgrport 7808

rmttrail/u01/oggmysql/dirdat/R3

passthru

gettruncates

tabletest.zw;

tablehr.tt;

infoall

Program     Status     Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING

EXTRACT     ABENDED    DPEA        00:00:00      95:05:49

EXTRACT     ABENDED    EXTA        00:00:00      95:05:54

EXTRACT     RUNNING    EXTMY3      00:00:00      00:00:08

EXTRACT     ABENDED    HRDPEA      00:00:00      95:05:49

EXTRACT     ABENDED    HREXTA      00:00:00      95:05:54

EXTRACT     RUNNING    PUMPMY3     00:00:00      00:00:05

配置     defegn

因为这里是oracle到mysql的同步,所以要生成异构的文件,并将文件复制到target端的dirdef目录下

在Oracle数据库执行

GGSCI(host01.example.com) 7> edit param defgen

useridogg,password ogg

defsfile/u01/ogg/dbhome/dirdef/oracle.def

tabletest.zw;

tablehr.tt

出现如下错:

OGG-00396  Command not terminated by semi-colon.

ERROR   OGG-01668 PROCESS ABENDING.

原因是配置文件中没有以分号结尾;

解决办法:修改配置文件。

defgenparamfile /u01/ogg/dbhome/dirprm/defgen.prm

scp oracle.def [email protected]:/u01/oggmysql/dirdef/

四:

target

端配置replicat进程

修改mysql密码

target

端配置replicat进程

mysqladmin-u root password "root123"

-

-

创建

checkpoint

table

GGSCI(host02.example.com DBLOGIN as root) 4> dblogin sourcedb test,useridroot,password root123

Successfullylogged into database.

addcheckpointtable test.checkpoint

GGSCI(host02.example.com DBLOGIN as root) 5> add replicat r3,exttrail/u01/oggmysql/dirdat/R3,checkpointtable test.checkpoint

--

修改参数

GGSCI(host02.example.com DBLOGIN as root) 6> view param R3

replicat  R3

dboptionshost localhost,connectionport 3306

targetdbtest,userid root,password root123

sourcedefs/u01/oggmysql/dirdef/oracle.def

handlecollisions

assumetargetdefs

discardfile/u01/oggmysql/dirrpt/R3.dsc,append,megabytes 50

maptest.zw,target test.zw;

map  hr.tt,target test.tt;

GGSCI(host02.example.com DBLOGIN as root) 7> start  r3

五:

测试

SQL>insert into  hr.tt values ('3');

1row created.

SQL>

SQL>commit ;

mysql>select * from test.tt;

+------+

|id   |

+------+

|2    |

|2    |

|3    |

+------+

3rows in set (0.00 sec)

select* from test.zw ;

ID NAME

------------------------------

1 missa

2 rita

3 ardu

SQL>insert into test.zw  values (5,'ogg');

1row created.

SQL>commit ;

Commitcomplete.

SQL>select * from test.zw ;

ID NAME

------------------------------

1 missa

2 rita

3 ardu

5 ogg

select* from test.zw;

+----+------+

|id | name |

+----+------+

|  3 | ardu |

+----+------+

1row in set (0.00 sec)

mysql>select * from test.zw;

+----+------+

|id | name |

+----+------+

|  3 | ardu |

|  5 | ogg |

+----+------+

2rows in set (0.00 sec)

deletefrom test.zw where  id='3';

1row deleted.

SQL>commit ;

Commitcomplete.

SQL>/

Commitcomplete.

SQL>select * from test.zw ;

ID NAME

------------------------------

1 missa

2 rita

5 ogg

mysql>select * from test.zw;

+----+------+

|id | name |

+----+------+

|  5 | ogg |

+----+------+

1row in set (0.00 sec)

至此,配置完毕。

你可能感兴趣的:(oracle异构mysql)