通過goldengate從ORACLE向mysql的單向複製
環境:我使用VBOX虛擬機器,一臺已經安裝ORACLE資料庫與GOLDENDGATE的主機。另一臺只安裝了ORACLE資料庫。
配置資料庫環境、goldengate使用者,安裝goldengate等操作參考:http://blog.csdn.net/q947817003/article/details/13293751
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@bys2 ~]# rpm -qa mysql
[root@bys2 ~]# cd /mnt/cdrom/
[root@bys2 cdrom]# yum -y install mysql
安裝伺服器端
[root@bys2 cdrom]# yum -y install mysql-server
[root@bys2 cdrom]# rpm -qa mysql*
mysql-5.0.77-4.el5_6.6
mysql-server-5.0.77-4.el5_6.6
##########################
啟動MYSQL
[root@bys2 cdrom]# service mysqld status
mysqld is stopped
[root@bys2 cdrom]# service mysqld start
Starting MySQL: [ OK ]
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql> create database oggtest;
Query OK, 1 row affected (0.00 sec)
mysql> use oggtest;
Database changed
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'ogg'@'%' identified by 'ogg';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> use oggtest
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table test5(aa int primary key) engine=innodb;
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+-------------------+
| Tables_in_oggtest |
+-------------------+
| test5 |
+-------------------+
1 row in set (0.00 sec)
mysql> select * from test5;
Empty set (0.01 sec)
退出後使用[oracle@bys2 mysqlogg]$ mysql -u root -p 進行登陸測試,確認使用 root使用者及密碼可以登陸。
如不能登陸,可以參考:http://blog.csdn.net/q947817003/article/details/13295099
###########################################
二.安裝OGG-FOR-MYSQL
[oracle@bys2 ~]$ tar -xvf ggs_Linux_x86_MySQL_32bit.tar -C /u01/mysqlogg/
[oracle@bys2 mysqlogg]$ pwd
/u01/mysqlogg
[oracle@bys2 mysqlogg]$ ./ggsci
Oracle GoldenGate Command Interpreter 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:29:30
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
GGSCI (bys2.oel.com) 1> create subdirs
Creating subdirectories under current directory /u01/mysqlogg
Parameter files /u01/mysqlogg/dirprm: already exists
Report files /u01/mysqlogg/dirrpt: created
Checkpoint files /u01/mysqlogg/dirchk: created
Process status files /u01/mysqlogg/dirpcs: created
SQL script files /u01/mysqlogg/dirsql: created
Database definitions files /u01/mysqlogg/dirdef: created
Extract data files /u01/mysqlogg/dirdat: created
Temporary files /u01/mysqlogg/dirtmp: created
Stdout files /u01/mysqlogg/dirout: created
ORACLE源端使用使用者TEST5的TEST5表。
PORT 7810
PURGEOLDEXTRACTS ./dirdat, USECHECKPOINTS, MINKEEPDAYS 10
GGSCI (bys2.oel.com) 2> edit params ./globals
eckpointtable oggtest.chktab
Password:
Successfully logged into database.
執行這兩條命令:
add checkpointtable oggtest.chktab
add replicat repmysql,exttrail /u01/mysqlogg/dirdat/my,checkpointtable oggtest.chktab
編輯配置檔案
edit params repmysql
內容如下: --MAPS語句注意使用者和表的對應
replicat repmysql
sourcedefs ./dirdef/to_mysql.def
handlecollisions
assumetargetdefs
applynoopupdates
sourcedb oggtest,userid root,password 123456
discardfile ./dirdat/repmysql.dsc,append,megabytes 50
map test5.test5,target oggtest.test5;
add extract extmysql,tranlog, begin now
目標端檔案的位置--這裡要注意rmttrail指的是目標端的路徑。
add rmttrail /u01/mysqlogg/dirdat/my, extract extmysql
edit params extmysql
在開啟的編輯視窗寫入
extract extmysql
userid ogg, password ogg
rmthost 192.168.1.213, mgrport 7810
rmttrail /u01/mysqlogg/dirdat/my
table test5.test5;
defsfile ./dirdef/to_mysql.def
userid ogg,password ogg
table test5.test5;
[oracle@bys001 ogg]$ ./defgen paramfile ./dirprm/defgen.prm
[oracle@bys001 dirdef]$ pwd
/u01/ogg/dirdef
[oracle@bys001 dirdef]$ ls
to_mysql.def
[oracle@bys001 dirdef]$ scp to_mysql.def 192.168.1.213:/u01/mysqlogg/dirdef
to_mysql.def 100% 912 0.9KB/s 00:00
需要在目標庫MYSQL中建立OGGTEST庫的TEST5表,
ORACLE源端使用使用者TEST5的TEST5表。
ORACEL資料庫中建立使用者和表所使用的語句如下:
使用DBA使用者執行 create user test5 inentified by test5;
grant connect,resource to test5;
conn test5/test5
create table test5(aa int primary key);
MYSQL中使用的語句如下:--第一步已經執行過。
mysql> create database oggtest;
mysql> use oggtest;
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
mysql> grant all privileges on *.* to 'ogg'@'%' identified by 'ogg';
mysql> flush privileges;
mysql> use oggtest
mysql> create table test5(aa int primary key) engine=innodb;
開啟程式所使用的語句大致如下:
start mgr
start extract extmysql 或start extmysql
start replicat repmysql 或start repmysql
雙方程式開啟後狀態如下:
源端: EXT1 EXT3 PUMP3 REP2是配置其它複製操作時用的。做ORACLE-MYSQL複製時不用管就可以。
GGSCI (bys001.oel.com) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT ABENDED EXT1 00:00:00 18:19:25
EXTRACT ABENDED EXT3 00:00:00 18:17:24
EXTRACT RUNNING EXTMYSQL 00:00:00 00:00:00
EXTRACT ABENDED PUMP3 00:00:00 18:19:28
REPLICAT ABENDED REP2 00:00:00 18:17:28
目標端:
GGSCI (bys2.oel.com) 4> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING REPMYSQL 00:00:00 00:00:08
TEST5@bys1>select * from test5;
no rows selected
TEST5@bys1>set time on
16:29:59 TEST5@bys1>insert into test5 values(100);
1 row created.
16:30:09 TEST5@bys1>commit;
Commit complete.
16:30:11 TEST5@bys1>insert into test5 values(200);
1 row created.
16:32:18 TEST5@bys1>commit;
Commit complete.
16:32:20 TEST5@bys1>select * from test5;
AA
----------
100
200
###################################
MYSQL端:
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select * from chktab;
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
| group_name | group_key | seqno | rba | audit_ts | create_ts | last_update_ts | current_dir |
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
| REPMYSQL | 2345303211 | 1 | 1543 | 2013-08-30 16:28:02.856500 | 2013-08-30 14:14:31 | 2013-08-30 16:28:31 | /u01/mysqlogg |
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
1 row in set (0.00 sec)
mysql> select * from test5;
+-----+
| aa |
+-----+
| 100 |
+-----+
1 row in set (0.00 sec)
mysql> select * from test5;
+-----+
| aa |
+-----+
| 100 |
| 200 |
+-----+
2 rows in set (0.01 sec)
mysql> select * from chktab;
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
| group_name | group_key | seqno | rba | audit_ts | create_ts | last_update_ts | current_dir |
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
| REPMYSQL | 2345303211 | 1 | 1790 | 2013-08-30 16:32:07.728727 | 2013-08-30 14:14:31 |2013-08-30 16:32:11 | /u01/mysqlogg |
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
1 row in set (0.00 sec)
配置資料庫環境、goldengate使用者,安裝goldengate等操作參考:http://blog.csdn.net/q947817003/article/details/13293751
一.安裝MYSQL
安裝MYSQL資料庫客戶端:
[root@bys2 ~]# mount /dev/cdrom /mnt/cdrom/mount: block device /dev/cdrom is write-protected, mounting read-only
[root@bys2 ~]# rpm -qa mysql
[root@bys2 ~]# cd /mnt/cdrom/
[root@bys2 cdrom]# yum -y install mysql
安裝伺服器端
[root@bys2 cdrom]# yum -y install mysql-server
[root@bys2 cdrom]# rpm -qa mysql*
mysql-5.0.77-4.el5_6.6
mysql-server-5.0.77-4.el5_6.6
##########################
啟動MYSQL
[root@bys2 cdrom]# service mysqld status
mysqld is stopped
[root@bys2 cdrom]# service mysqld start
Starting MySQL: [ OK ]
建立用來做同步的使用者和表
[oracle@bys2 ~]$ mysql -u rootmysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql> create database oggtest;
Query OK, 1 row affected (0.00 sec)
mysql> use oggtest;
Database changed
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'ogg'@'%' identified by 'ogg';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> use oggtest
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table test5(aa int primary key) engine=innodb;
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+-------------------+
| Tables_in_oggtest |
+-------------------+
| test5 |
+-------------------+
1 row in set (0.00 sec)
mysql> select * from test5;
Empty set (0.01 sec)
退出後使用[oracle@bys2 mysqlogg]$ mysql -u root -p 進行登陸測試,確認使用 root使用者及密碼可以登陸。
如不能登陸,可以參考:http://blog.csdn.net/q947817003/article/details/13295099
###########################################
二.安裝OGG-FOR-MYSQL
[oracle@bys2 ~]$ tar -xvf ggs_Linux_x86_MySQL_32bit.tar -C /u01/mysqlogg/
[oracle@bys2 mysqlogg]$ pwd
/u01/mysqlogg
[oracle@bys2 mysqlogg]$ ./ggsci
Oracle GoldenGate Command Interpreter 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:29:30
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
GGSCI (bys2.oel.com) 1> create subdirs
Creating subdirectories under current directory /u01/mysqlogg
Parameter files /u01/mysqlogg/dirprm: already exists
Report files /u01/mysqlogg/dirrpt: created
Checkpoint files /u01/mysqlogg/dirchk: created
Process status files /u01/mysqlogg/dirpcs: created
SQL script files /u01/mysqlogg/dirsql: created
Database definitions files /u01/mysqlogg/dirdef: created
Extract data files /u01/mysqlogg/dirdat: created
Temporary files /u01/mysqlogg/dirtmp: created
Stdout files /u01/mysqlogg/dirout: created
三.配置目標端OGG
首先規劃一下,目標庫啟動的PORT 是7810 , MYSQL設定同步的是:OGGTEST庫的TEST5表,ORACLE源端使用使用者TEST5的TEST5表。
1.配置MGR程式
GGSCI (bys2.oel.com) 4> edit params mgrPORT 7810
PURGEOLDEXTRACTS ./dirdat, USECHECKPOINTS, MINKEEPDAYS 10
GGSCI (bys2.oel.com) 2> edit params ./globals
eckpointtable oggtest.chktab
2.登陸並配置 replicat 程式
GGSCI (bys2.oel.com) 1> dblogin sourcedb oggtest,userid rootPassword:
Successfully logged into database.
執行這兩條命令:
add checkpointtable oggtest.chktab
add replicat repmysql,exttrail /u01/mysqlogg/dirdat/my,checkpointtable oggtest.chktab
編輯配置檔案
edit params repmysql
內容如下: --MAPS語句注意使用者和表的對應
replicat repmysql
sourcedefs ./dirdef/to_mysql.def
handlecollisions
assumetargetdefs
applynoopupdates
sourcedb oggtest,userid root,password 123456
discardfile ./dirdat/repmysql.dsc,append,megabytes 50
map test5.test5,target oggtest.test5;
四.配置源端資料庫--不使用PUMP方式。
1.MGR程式已經配置過,配置extract程式
按順序執行以下操作:add extract extmysql,tranlog, begin now
目標端檔案的位置--這裡要注意rmttrail指的是目標端的路徑。
add rmttrail /u01/mysqlogg/dirdat/my, extract extmysql
edit params extmysql
在開啟的編輯視窗寫入
extract extmysql
userid ogg, password ogg
rmthost 192.168.1.213, mgrport 7810
rmttrail /u01/mysqlogg/dirdat/my
table test5.test5;
2.源庫上生成物件定義檔案,並將此檔案複製到目標庫(MYSQL端)的 ogg/dirdef 下
GGSCI (node1.example.com) 21> edit params defgendefsfile ./dirdef/to_mysql.def
userid ogg,password ogg
table test5.test5;
[oracle@bys001 ogg]$ ./defgen paramfile ./dirprm/defgen.prm
[oracle@bys001 dirdef]$ pwd
/u01/ogg/dirdef
[oracle@bys001 dirdef]$ ls
to_mysql.def
[oracle@bys001 dirdef]$ scp to_mysql.def 192.168.1.213:/u01/mysqlogg/dirdef
to_mysql.def 100% 912 0.9KB/s 00:00
五、初始化資料並開啟雙方程式
初始化資料是建立相應的使用者和表。需要在目標庫MYSQL中建立OGGTEST庫的TEST5表,
ORACLE源端使用使用者TEST5的TEST5表。
ORACEL資料庫中建立使用者和表所使用的語句如下:
使用DBA使用者執行 create user test5 inentified by test5;
grant connect,resource to test5;
conn test5/test5
create table test5(aa int primary key);
MYSQL中使用的語句如下:--第一步已經執行過。
mysql> create database oggtest;
mysql> use oggtest;
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
mysql> grant all privileges on *.* to 'ogg'@'%' identified by 'ogg';
mysql> flush privileges;
mysql> use oggtest
mysql> create table test5(aa int primary key) engine=innodb;
開啟程式所使用的語句大致如下:
start mgr
start extract extmysql 或start extmysql
start replicat repmysql 或start repmysql
雙方程式開啟後狀態如下:
源端: EXT1 EXT3 PUMP3 REP2是配置其它複製操作時用的。做ORACLE-MYSQL複製時不用管就可以。
GGSCI (bys001.oel.com) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT ABENDED EXT1 00:00:00 18:19:25
EXTRACT ABENDED EXT3 00:00:00 18:17:24
EXTRACT RUNNING EXTMYSQL 00:00:00 00:00:00
EXTRACT ABENDED PUMP3 00:00:00 18:19:28
REPLICAT ABENDED REP2 00:00:00 18:17:28
目標端:
GGSCI (bys2.oel.com) 4> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING REPMYSQL 00:00:00 00:00:08
六、資料同步測試
ORACLE源端操作:
[oracle@bys001 ogg]$ sqlplus test5/test5TEST5@bys1>select * from test5;
no rows selected
TEST5@bys1>set time on
16:29:59 TEST5@bys1>insert into test5 values(100);
1 row created.
16:30:09 TEST5@bys1>commit;
Commit complete.
16:30:11 TEST5@bys1>insert into test5 values(200);
1 row created.
16:32:18 TEST5@bys1>commit;
Commit complete.
16:32:20 TEST5@bys1>select * from test5;
AA
----------
100
200
###################################
MYSQL端:
兩次在ORACLE資料庫中的提交,在MYSQL中的chktab;表的 audit_ts 列, last_update_ts 列均有更新。可能是ORACLE與MYSQL不在同一主機,時間未做同步,兩端更新的時間並不一致。
[oracle@bys2 mysqlogg]$ mysql -u root -p oggtestType 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select * from chktab;
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
| group_name | group_key | seqno | rba | audit_ts | create_ts | last_update_ts | current_dir |
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
| REPMYSQL | 2345303211 | 1 | 1543 | 2013-08-30 16:28:02.856500 | 2013-08-30 14:14:31 | 2013-08-30 16:28:31 | /u01/mysqlogg |
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
1 row in set (0.00 sec)
mysql> select * from test5;
+-----+
| aa |
+-----+
| 100 |
+-----+
1 row in set (0.00 sec)
mysql> select * from test5;
+-----+
| aa |
+-----+
| 100 |
| 200 |
+-----+
2 rows in set (0.01 sec)
mysql> select * from chktab;
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
| group_name | group_key | seqno | rba | audit_ts | create_ts | last_update_ts | current_dir |
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
| REPMYSQL | 2345303211 | 1 | 1790 | 2013-08-30 16:32:07.728727 | 2013-08-30 14:14:31 |2013-08-30 16:32:11 | /u01/mysqlogg |
+------------+------------+-------+------+----------------------------+---------------------+---------------------+---------------+
1 row in set (0.00 sec)
相關文章
- 用python生成oracle goldengate複製配置檔案PythonOracleGo
- PostgreSQL雙向複製教程SQL
- 簡單搭建MySQL主從複製MySql
- 從單向到雙向資料繫結
- mysql複製--主從複製配置MySql
- MySQL的主從複製MySql
- HTTPS連線建立過程(單向&雙向)HTTP
- Linux下MySQL主從複製(Binlog)的部署過程LinuxMySql
- MySQL主從複製之GTID複製MySql
- MySQL主從複製MySql
- 聊聊MySQL主從複製的幾種複製方式MySql
- MySQL 主從複製過濾新增庫表過濾方案MySql
- MySQL主從複製之半同步複製MySql
- MySQL主從複製之非同步複製MySql非同步
- 簡單實踐實現 MySQL 主從複製MySql
- MySQL主從複製原理MySql
- mysql--主從複製MySql
- mysql 8.4 主從複製MySql
- mysql主從複製搭建MySql
- MySQL 的主從複製實踐MySql
- 架構系列---餓了麼MySQL異地多活的資料雙向複製架構MySql
- MySQL++:Liunx - MySQL 主從複製MySql
- MySQL(13)---MYSQL主從複製原理MySql
- mysql過濾複製的實現MySql
- mysql5.7主從複製,主主複製MySql
- MySQL 主從複製之多執行緒複製MySql執行緒
- OGG雙向條件複製的部署與測試
- 從單體邁向 Serverless 的避坑指南Server
- MYSQL主從複製製作配置方案MySql
- MySQL5.7主從複製-半同步複製搭建MySql
- windows 下mysql主從複製WindowsMySql
- mysql實現主從複製MySql
- mysql主從延遲複製MySql
- MySQL 主從複製實操MySql
- MYSQL主從複製配置(整理)MySql
- MySQL主從複製歷程MySql
- MySQL-18.主從複製MySql
- Windows Mysql主從複製部署WindowsMySql
- Mysql 傳統主從複製MySql