goldengate 12.3 實現mysql資料及DDL實時同步

margiex發表於2017-08-22
以下環境在mysql 5.7上完成。
set mysql_home=mysql安裝路徑
set path=%mysql_home%\bin;%path%
首先要準備mysql的啟動,可參考:http://silentwu.iteye.com/blog/2308722
由於需要使用OGG解析日誌,所以需要在my.ini/my.cnf中設定如下引數
log-bin=u:/soft/mysql/5.7/mysql-5.7.19-winx64/logs/log-bin
binlog-ignore-db=oggddl
binlog_format=row

 

如果需要同步DDL,則需要在OGG安裝目錄下執行:
ddl_install.cmd/sh install root "root_password" 3306

 

重啟mysql,使引數生效。
 

準備測試庫表和使用者

 
--源庫
create database testdb charset utf8;
use testdb;
create table tb1(id int primary key, name varchar(50));

 

 

--目標庫
create database tgtdb charset utf8;
use tgtdb;
create table tgtdb.tb1(id int primary key, name varchar(50));
 

--同步使用者
create user 'ogg'@'%' identified by 'ogg';
GRANT ALL PRIVILEGES ON *.* TO 'ogg'@'%' IDENTIFIED BY 'ogg' WITH GRANT OPTION; 
FLUSH   PRIVILEGES;

以下配置在同一節點上完成,所以不需要傳輸程式。

抽取程式引數ex1.prm
extract ex1
sourcedb testdb@localhost, userid ogg, password ogg
TRANLOGOPTIONS ALTLOGDEST "u:\\soft\\mysql\\5.7\\mysql-5.7.19-winx64\\logs\\log-bin.index"
exttrail ./dirdat/ea
ddl include mapped
table testdb.*;

 

 

add extract ex1, tranlog, begin now
add exttrail ./dirdat/ea, extract ex1
 

投遞程式引數re1.prm

replicat re1
targetdb tgtdb@localhost, userid ogg, password ogg
AssumeTargetDefs
map testdb.*, target tgtdb.*;


add replicat re1, exttrail ./dirdat/ea, nodbcheckpoint

-- DML測試
insert into testdb.tb1 values(1,'bbc');
insert into testdb.tb1 values(2,'bdsfbc');
 

- DDL 測試
create table testdb.tb2(id int primary key, name varchar(50));
alter table testdb.tb2 add age int;
insert into testdb.tb2 values(2, 'cdl',40);

 

相關文章