通过goldengate从ORACLE向mysql的单向复制 环境:我使用VBOX虚拟机,一台已经安装ORACLE数据库与GOLDENDGATE的主机。另一台只安装了ORACLE数据库。 配置数据库环境、goldengate用户,安装goldengate等操作参考:http://blog.csdn.net/q947817003/article/deta
通过goldengate从ORACLE向mysql的单向复制
环境:我使用VBOX虚拟机,一台已经安装ORACLE数据库与GOLDENDGATE的主机。另一台只安装了ORACLE数据库。
配置数据库环境、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 root
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
三.配置目标端OGG
首先规划一下,目标库启动的PORT 是7810 , MYSQL设置同步的是:OGGTEST库的TEST5表,
ORACLE源端使用用户TEST5的TEST5表。
1.配置MGR进程
GGSCI (bys2.oel.com) 4> edit params mgr
PORT 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 root
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;
四.配置源端数据库--不使用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 defgen
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
六、数据同步测试
ORACLE源端操作:
[oracle@bys001 ogg]$ sqlplus test5/test5
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端:
两次在ORACLE数据库中的提交,在MYSQL中的chktab;表的 audit_ts 列, last_update_ts 列均有更新。可能是ORACLE与MYSQL不在同一主机,时间未做同步,两端更新的时间并不一致。
[oracle@bys2 mysqlogg]$ mysql -u root -p oggtest
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)