Oracle GoldenGate 之 SqlServer数据同步到Mysql数据库

项目描述:

将SqlSever 2008 R2中的数据实时或定时的同步到Mysql 5.6数据库中。

  OS DATABASE
来源数据库 Window 2008 MS SQL 2008 R2
目标数据库 Linux  MySQL 5.6


实施方案:

如何初始化数据?

Navicat  Premium--可以很方便的将MSSQL SERVER中的数据结构和数据初始化到Mysql数据库中。

如何实现实时同步?

方案1:SyncNavigator--实现MSSQL SERVER和Mysql数据库之间的数据同步(可选在调度时间和机制)。
方案2:Oracle Goldengate--灵活的实现MSSQL SERVER和Mysql数据库之间的数据同步。

两种方案的利弊?

方案1:,配置简单,但是对于目标端表中已经存在数据的情况处理麻烦(无法创建同步字段,这个字段是软件同步进程需要的)
方案2,配置复杂,效率高。

使用OGG来实现MSSQL SERVER和MYSQL之间的数据同步

OGG 软件:

V34020-01
Oracle GoldenGate V11.2.1.0.2 for SQL Server on Windows (64bit)
V32399-01
Oracle GoldenGate V11.2.1.0.1 for MySQL 5.x on Linux x86-64)

源端MSSQL SERVER配置

安装OGG

[plain]  view plain  copy
 print ?
  1. C:\OGG>ggsci  
  2.   
  3. Oracle GoldenGate Command Interpreter for SQL Server  
  4. Version 11.2.1.0.2 OGGCORE_11.2.1.0.2T3_PLATFORMS_120724.2205  
  5. Windows x64 (optimized), Microsoft SQL Server on Jul 25 2012 03:04:52  
  6.   
  7. Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.  
  8.   
  9.   
  10.   
  11. GGSCI (WIN-UGCMTTOTKE7) 1> create subdirs  
  12.   
  13. Creating subdirectories under current directory C:\OGG  
  14.   
  15. Parameter files                C:\OGG\dirprm: already exists  
  16. Report files                   C:\OGG\dirrpt: created  
  17. Checkpoint files               C:\OGG\dirchk: created  
  18. Process status files           C:\OGG\dirpcs: created  
  19. SQL script files               C:\OGG\dirsql: created  
  20. Database definitions files     C:\OGG\dirdef: created  
  21. Extract data files             C:\OGG\dirdat: created  
  22. Temporary files                C:\OGG\dirtmp: created  
  23. Stdout files                   C:\OGG\dirout: created  
  24.   
  25. GGSCI (WIN-UGCMTTOTKE7) 2>exit  
退出后,切换到OGG目录下
[plain]  view plain  copy
 print ?
  1. C:\OGG>INSTALL ADDSERVICE  
  2. Service 'GGSMGR' created.  
  3.   
  4. Install program terminated normally.  
  5. C:\OGG>  

配置ODBC数据源

[plain]  view plain  copy
 print ?
  1. Microsoft SQL Server ODBC 驱动程序版本 06.01.7601  
  2.   
  3.   
  4. 数据源名称: oa_test  
  5. 数据源描述:   
  6. 服务器: WIN-UGCMTTOTKE7  
  7. 数据库: (Default)  
  8. 语言: (Default)  
  9. 翻译字符数据: Yes  
  10. 日志长运行查询: No  
  11. 日志驱动程序统计: No  
  12. 使用区域设置: No  
  13. 预定义的语句选项: 在断开时删除临时存储过程  
  14. 使用故障转移服务器: No  
  15. 使用 ANSI 引用的标识符: Yes  
  16. 使用 ANSI 的空值,填充和警告: Yes  
  17. 数据加密: No  

配置OGG抽取进程

[plain]  view plain  copy
 print ?
  1. GGSCI (WIN-UGCMTTOTKE7) 8> dblogin sourcedb oa_test,userid yunwei,password "********"  
  2.   
  3. 2014-07-21 14:39:28  INFO    OGG-03036  Database character set identified as windows-936. Locale: zh_Hans_CN  
  4.   
  5. 2014-07-21 14:39:28  INFO    OGG-03037  Session character set identified as GBK.  
  6. Successfully logged into database.  
[plain]  view plain  copy
 print ?
  1. GGSCI (WIN-UGCMTTOTKE7) 12> add trandata dbo.TEmployees  
  2.   
  3.   
  4. 2014-07-21 14:43:51  WARNING OGG-01483  The key for table [oa_test.dbo.TEmployees] contains one or more variable length  
  5. columns.  These columns may not have their pre-images written to the transaction log during updates.  Please use KEYCOLS  
  6.  to specify a key for Oracle GoldenGate to use on this table.  
  7.   
  8.   
  9. Logging of supplemental log data is enabled for table dbo.TEmployees  
  10.   
  11.   
  12. GGSCI (WIN-UGCMTTOTKE7) 13> add trandata dbo.TRecords  
  13.   
  14.   
  15. 2014-07-21 14:46:04  WARNING OGG-01483  The key for table [oa_test.dbo.TRecords] contains one or more variable length co  
  16. lumns.  These columns may not have their pre-images written to the transaction log during updates.  Please use KEYCOLS to specify a key for Oracle GoldenGate to use on this table.  
  17.   
  18.   
  19. Logging of supplemental log data is enabled for table dbo.TRecords  
  20.   
  21.   
  22. GGSCI (WIN-UGCMTTOTKE7) 14> edit params oa  
[plain]  view plain  copy
 print ?
  1. 编辑如下内容:  
[plain]  view plain  copy
 print ?
  1. defsfile c:\ogg\dirdef\oa.def  
  2. sourcedb oa_test,userid yunwei,password "******"  
  3. table dbo.TEmployees;  
  4. table dbo.TRecords;  
[plain]  view plain  copy
 print ?
  1. 执行生成表结构定义文件  
[plain]  view plain  copy
 print ?
  1. C:\OGG>defgen paramfile c:\ogg\dirprm\oa.prm  
将新生成的def文件拷贝到目标端!


查看mssql数据库处于完全恢复模式。


[plain]  view plain  copy
 print ?
  1. GGSCI (WIN-UGCMTTOTKE7) 3> edit param mgr  
填写如下内容:
port 7809

[plain]  view plain  copy
 print ?
  1. GGSCI (WIN-UGCMTTOTKE7) 5> start mgr  
  2.   
  3. Starting Manager as service ('GGSMGR')...  
  4. Service started.  
[plain]  view plain  copy
 print ?
  1. GGSCI (WIN-UGCMTTOTKE7) 8> info all  
  2.   
  3. Program     Status      Group       Lag at Chkpt  Time Since C  
  4. MANAGER     RUNNING  
  5.   
  6. GGSCI (WIN-UGCMTTOTKE7) 9> add extract emssql,tranlog,begin now  
  7. EXTRACT added.  
  8.   
  9. GGSCI (WIN-UGCMTTOTKE7) 10> add rmttrail ./dirdat/ms,extract emssql  
  10. RMTTRAIL added.  
[plain]  view plain  copy
 print ?
  1. GGSCI (WIN-UGCMTTOTKE7) 11> edit params emssql  
编辑内容如下:
EXTRACT EMSSQL
SOURCEDB oa_test,userid yunwei,password "******"
TRANLOGOPTIONS MANAGESECONDARYTRUNCATIONPOINT
RMTHOST 192.168.2.34, MGRPORT 7809
RMTTRAIL ./dirdat/ms
TABLE dbo.TEmployees;
TABLE dbo.TRecords;

执行全库备份。然后启动进程。并且 trunc. log on chkpt要设置为false

目标端MYSQL配置:

安装:

可参考mysql版本的OGG安装步骤,大同小异

配置复制进程:

[plain]  view plain  copy
 print ?
  1. GGSCI (localhost.localdomain) 2> dblogin sourcedb [email protected]:3306,userid root,password xxxx  
  2. Successfully logged into database.  
[plain]  view plain  copy
 print ?
  1. GGSCI (localhost.localdomain) 3> add replicat rmysql,exttrail ./dirdat/ms,nodbcheckpoint  
  2. REPLICAT added.  
  3.   
  4. GGSCI (localhost.localdomain) 4> edit params rmysql  
[plain]  view plain  copy
 print ?
  1.   
填写如下内容:
replicat rmysql
TARGETDB [email protected]:3306,userid root,password xxx
assumetargetdefs
sourcedefs ./dirdef/oa.def
reperror default,discard
discardfile ./dirrpt/rmysql.dsc,append,megabytes 100
MAP dbo.TEmployees,TARGET oa.temployees,keycols(Employee_ID);
MAP dbo.TRecords,TARGET oa.trecords,keycols(Record_ID),colmap(usedefaults,RinOut=inOut);

至此!配置完成。
接下来就是进行insert update delete测试。

小插曲:

Sql  server表中的bit数据类型在抓换到mysql中时为bool(tinyint)类型,这时候ogg会报错,提示类型不匹配。需要手动将mysql中的相关类型设置为char(1)就OK了。

你可能感兴趣的:(基于DB日志实时数据传输,sqlserver到mysql)