如圖所示:源端採用Mysql庫,目標端採用Oracle庫mysql
1、OGG安裝配置(源端)sql
1、OGG下載數據庫
https://edelivery.oracle.com/EPD/Download/get_form?egroup_aru_number=14841438bash
※Mysql to Oracle注意事項※oracle
1. 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)
2.Oracle GoldenGate supports InnoDB storage engine for a source MySQL database
goldengate對mysql只支持innodb引擎
因此,在建立mysql端的表的時候,要指定表爲innodb引擎。
create table test.test2(id int,name varchar(10)) engine=innodb;
3.【版本問題】當前for mysql版本的ogg11.2.1.0.1,暫不支持mysql 5.0如下,以及mysql 5.6以上。
4.【配置問題】mysql跟oracle的區別是,mysql是靠各個數據庫來劃分表,而oracle是靠用戶來劃分表,因此在配置以mysql爲源端的時候,
mysql端 [table test.test2] test指的是數據庫的名字,可是若是是oracle作源端的時候,test指的就是用戶的名字了,這裏有所區分。app
2、源端mysql庫配置socket
- 建立mysql用戶
*********************************************************************************************
注:建立mysql用戶的目的是要把goldengate安裝到mysql用戶下,
不然當ogg讀取mysql二進制索引文件
[log-bin-index=/var/lib/mysql/binary-log.index]
的時候沒有相關權限。
***********************************************************************************************
建立mysql用戶:
groupadd -g 1000 mysql
useradd -u 1000 -g mysql mysql
passwd mysql
密碼:mysql
掛載鏡像,配置yum源,內容以下:測試
[myyum]ui
name=myyumurl
baseurl=file:///mnt
enabled=1
gpgcheck=1
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7
- 安裝mysql數據庫(root)
安裝mysql:
[root@localhost lib]# yum install -y mariadb*
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 mariadb.x86_64.1.5.5.60-1.el7_5 將被 安裝
---> 軟件包 mariadb-bench.x86_64.1.5.5.60-1.el7_5 將被 安裝
---> 軟件包 mariadb-devel.x86_64.1.5.5.60-1.el7_5 將被 安裝
---> 軟件包 mariadb-libs.x86_64.1.5.5.60-1.el7_5 將被 安裝
---> 軟件包 mariadb-server.x86_64.1.5.5.60-1.el7_5 將被 安裝
--> 正在處理依賴關係 perl-DBD-MySQL,它被軟件包 1:mariadb-server-5.5.60-1.el7_5.x86_64 須要
---> 軟件包 mariadb-test.x86_64.1.5.5.60-1.el7_5 將被 安裝
--> 正在檢查事務
---> 軟件包 perl-DBD-MySQL.x86_64.0.4.023-6.el7 將被 安裝
--> 解決依賴關係完成
…………………………………………………………………
…………………………………….省略
已安裝:
mariadb.x86_64 1:5.5.60-1.el7_5 mariadb-bench.x86_64 1:5.5.60-1.el7_5
mariadb-devel.x86_64 1:5.5.60-1.el7_5 mariadb-libs.x86_64 1:5.5.60-1.el7_5
mariadb-server.x86_64 1:5.5.60-1.el7_5 mariadb-test.x86_64 1:5.5.60-1.el7_5
做爲依賴被安裝:
perl-DBD-MySQL.x86_64 0:4.023-6.el7
完畢!
設置root用戶登陸密碼:
[root@localhost lib]# /usr/bin/mysqladmin -u root -h localhost -s var/lib/mysql/mysql.sock password '123'
拷貝初始參數文件/etc下:
[root@mysql2 ~]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
配置參數文件,並開啓二進制日誌,日誌模式爲row:
[root@mysql2 ~]#vi /etc/my.cnf
# Replication Master Server (default)
# binary logging is required for replication
#log-bin=mysql-bin
log-bin-index=/var/lib/mysql/bin-log.index
# binary logging format – mixed recommended
binlog_format=row
啓動mysql:
查看設置的參數是否生效:
MariaDB [(none)]> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | ON |
+---------------+-------+
1 row in set (0.00 sec)
建立即將同步的表:
查看test2表的屬性:
3.安裝mysql版本的goldengate
用mysql用戶安裝ogg:
設置環境變量:
vi .bash_profile
export PATH=/home/mysql/ggs
export LD_LIBRARY_PATH=/home/mysql/ggs
變量生效:
Source . bash_profile
建立安裝目錄
su - mysql
cd /home/mysql
mkdir ggs
安裝ogg:
[root@localhost mysql]# cp /goldengate/ggs_Linux_x64_MySQL_64bit.tar /home/oracle/ggs
mysql@mysql2 ggs]$ tar -xvf ggs_Linux_x64_MySQL_64bit.tar
[mysql@mysql2 ggs]$ ./ggsci
GGSCI (mysql2) 1> create subdirs
GGSCI (mysql2) 2>dblogin sourcedb test@localhost:3306, userid root,password 123
若是報錯:
2013-08-14 19:53:41WARNING OGG-00769MySQL Login failed: . SQL error (2002). Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2).
ERROR: Failed to connect to MySQL database engine for HOST localhost, DATABASE test, USER root, PORT 3306.
解決辦法:
root and mysql user add follow line into .bash_profile
export MYSQL_UNIX_PORT=/var/lib/mysql/mysql.sock
source .bash_profile
GGSCI (ogg) 2> dblogin sourcedb test@localhost:3306,userid root,password 123 Successfully logged into database.
配置mgr: GGSCI (ogg) 3> edit param mgr port 7810 dynamicportlist 7800-8000 autorestart extract *,waitminutes 2,resetminutes 5
GGSCI (ogg) 4> start mgr Manager started. GGSCI (ogg) 5> info mgr Manager is running (IP port ogg.7810).
GGSCI (ogg) 6> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING
配置extract進程組: GGSCI (ogg) 7> edit param ext_1 extract ext_1 setenv (MYSQL_HOME=」/var/lib/mysql」) tranlogoptions altlogdest /var/lib/mysql/log-bin.index sourcedb test@localhost:3306,userid root,password 123 exttrail ./dirdat/e2 dynamicresolution gettruncates table test.test2;
GGSCI (ogg) 11> add extract ext_1,tranlog,begin now EXTRACT added. GGSCI (ogg) 12> add exttrail ./dirdat/e2,extract ext_1 EXTTRAIL added.
配置pump進程組: GGSCI (ogg) 13> edit params pump_1 extract pump_1 rmthost 192.168.1.13,mgrport 7810 rmttrail /goldengate/dirdat/e2 passthru gettruncates table test.test2;
GGSCI (ogg) 14> add extract pump_1,exttrailsource ./dirdat/e2 EXTRACT added.
GGSCI (ogg) 15> add rmttrail /goldengate/dirdat/e2,extract pump_1 RMTTRAIL added.
異構平臺配置defgen:
GGSCI (ogg) 16> edit params defgen defsfile ./dirdef/defgen.prm sourcedb test@localhost:3306, userid root,password 123 table test.test2;
[oracle@ogg ogg_ms]$ ./defgen paramfile dirprm/defgen.prm *********************************************************************** Oracle GoldenGate Table Definition Generator for MySQL Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230 Linux, x86, 32bit (optimized), MySQL Enterprise on Apr 23 2012 04:59:19 Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved. Starting at 2014-09-26 16:01:05 *********************************************************************** Operating System Version: Linux Version #1 SMP Wed Sep 1 01:26:34 EDT 2010, Release 2.6.32-71.el6.i686 Node: ogg Machine: i686 soft limit hard limit Address Space Size : unlimited unlimited Heap Size : unlimited unlimited File Size : unlimited unlimited CPU Time : unlimited unlimited Process id: 2606 *********************************************************************** ** Running with the following parameters ** *********************************************************************** defsfile /u01/ogg_ms/dirdef/defgen.prm sourcedb test@localhost:3306, userid root,password ****** table test.test2; Retrieving definition for test.test2 Definitions generated for 1 table in /u01/ogg_ms/dirdef/defgen.prm
傳送defgen文件到目標端: [oracle@ogg ogg_ms]$ scp dirdef/defgen.prm oracle@192.168.1.13:/goldengate/dirdef GGSCI (ogg) 5> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING EXTRACT ABENDED EXT_1 00:00:00 00:21:03 EXTRACT RUNNING PUMP_1 00:00:00 00:00:06
啓動extract和pump進程: GGSCI (ogg) 6> start extract ext_1 Sending START request to MANAGER ... EXTRACT EXT_1 starting GGSCI (ogg) 7> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EXT_1 00:00:00 00:21:17 EXTRACT RUNNING PUMP_1 00:00:00 00:00:09 |
如下是容易出現的故障,緣由是mysql版本不支持row
extract進程啓動異常(abended)!
查看日誌:
GGSCI (ogg) 36> view ggsevt
2014-09-26 17:24:56 INFO OGG-01053 Oracle GoldenGate Capture for MySQL, ext_1.prm: Recovery completed for target file ./dirdat/e20
00026, at RBA 961.
2014-09-26 17:24:56 INFO OGG-01057 Oracle GoldenGate Capture for MySQL, ext_1.prm: Recovery completed for all targets.
2014-09-26 17:24:56 INFO OGG-00182 Oracle GoldenGate Capture for MySQL, ext_1.prm: VAM API running in single-threaded mode.
2014-09-26 17:24:56 INFO OGG-01515 Oracle GoldenGate Capture for MySQL, ext_1.prm: Positioning to begin time Sep 26, 2014 3:52:01
PM.
2014-09-26 17:24:56 ERROR OGG-00146 Oracle GoldenGate Capture for MySQL, ext_1.prm: VAM function VAMInitialize returned unexpected
result: error 600 - VAM Client Report <CAUSE OF FAILURE : ERROR NO 13 - Failed to access index file : Check File PATH/EXISTENCE/PERMISSI
ONS - /var/lib/mysql/mysql-bin.index
WHEN FAILED : While initializing binary log configuration
WHERE FAILED : MySQLBinLog Reader Module
CONTEXT OF FAILURE : No Information Available!>.
2014-09-26 17:24:56 ERROR OGG-01668 Oracle GoldenGate Capture for MySQL, ext_1.prm: PROCESS ABENDING.
4、目標端ogg配置
配置MGR GGSCI (rh6.cuug.net) 4> edit params mgr port 7810 dynamicportlist 7800-8000 autorestart extract *,waitminutes 2,resetminutes 5 ~ GGSCI (rh6.cuug.net) 5> start mgr Manager started. GGSCI (rh6.cuug.net) 6> info mgr Manager is running (IP port rh6.cuug.net.7810).
配置replicat進程組: [oracle@rh6 ogg]$ ./ggsci Oracle GoldenGate Command Interpreter for Oracle Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO Linux, x86, 32bit (optimized), Oracle 11g on Apr 23 2012 08:09:25 Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved. GGSCI (rh6.cuug.net) 1> GGSCI (rh6.cuug.net) 1> edit param rep_1 replicat rep_1 sourcedefs ./dirdef/defgen.prm userid goldengate,password goldengate reperror default,discard discardfile ./dirrpt/rep_1.dsc,append,megabytes 50 dynamicresolution gettruncates map test.test2, target test.test3;
GGSCI (rh6.cuug.net) 1>add replicat rep_1,exttrail ./dirdat/e2 REPLICAT added.
啓動mgr和replicat進程: GGSCI (rh6.cuug.net) 3> start mgr Manager started. GGSCI (rh6.cuug.net) 4> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING REPLICAT STOPPED REP_1 00:00:00 00:00:34
GGSCI (rh6.cuug.net) 5> start replicat rep_1 Sending START request to MANAGER ... REPLICAT REP_1 starting GGSCI (rh6.cuug.net) 6> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING REPLICAT RUNNING REP_1 00:00:00 00:00:00 |
五.進行dml測試
能夠分別用不一樣的用戶對源端mysql數據庫中 test庫下的test2表進行insert、delete、update測試。
查看目標端oracle數據庫下的itpux用戶下的test3表是否同步成功。
源端insert:
目標端:
源端update:
目標端:
源端truncate(抽取,複製進程添加「gettruncates」參數)
目標端:
測試完畢。