環境:11.2.0.3(已安裝數據庫實例)+OEL5.7php
192.168.1.55 zlm sid:zlm11ghtml
192.168.1.60 zlm2 sid:zlm11gmysql
1、安裝軟件,配置環境,建立相關用戶web
1.1 下載介質並安裝OGG軟件sql
從官方網址下載最新版OGG FOR ORACLE 11g ON LINUX X86-64軟件:shell
http://www.oracle.com/technetwork/middleware/goldengate/downloads/index.html?ssSourceSiteId=ocomen數據庫
Oracle GoldenGate V11.2.1.0.1 for Oracle 11g on Linux x86-64 (86 MB) 安全
介質名稱:ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zipbash
1.2 把OGG軟件包複製到源端oracle主目錄,建立安裝目錄gg11後2次解壓到gg11session
[oracle@zlm ~]$ ls
ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zip
[oracle@zlm ~]$ cd $OACLE_BASE
[oracle@zlm oracle]$ mkdir gg11
[oracle@zlm oracle]$ cd gg11
[oracle@zlm gg11]$ unzip /home/oracle/ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zip
[oracle@zlm gg11]$ ll
total 223764
-rw-rw-r-- 1 oracle oinstall 228556800 Apr 23 2012 fbo_ggs_Linux_x64_ora11g_64bit.tar
-rwxrwxrwx 1 oracle oinstall 220546 May 2 2012 OGG_WinUnix_Rel_Notes_11.2.1.0.1.pdf
-rwxrwxrwx 1 oracle oinstall 93696 May 2 2012 Oracle GoldenGate 11.2.1.0.1 README.doc
-rwxrwxrwx 1 oracle oinstall 24390 May 2 2012 Oracle GoldenGate 11.2.1.0.1 README.txt
[oracle@zlm gg11]$ tar xvof fbo_ggs_Linux_x64_ora11g_64bit.tar
1.3 修改環境變量文件.bash_profile,加入OGG的環境變量
export GGHOME=$ORACLE_BASE/gg11
export PATH=$ORACLE_BASE/gg11:$ORACLE_HOME/bin:/usr/bin/:$PATH
[oracle@zlm gg11]$ . ~/.bash_profile
[oracle@zlm gg11]$ ggsci
ggsci: error while loading shared libraries: libnnz11.so: cannot open shared object file: No such file or directory
因爲沒有設置LD_LIBRARY_PATH環境變量,因此沒法執行ggsci,添加export LD_LIBLARY_PATH=$ORACLE_BASE/gg11:$ORACLE_HOME/lib:$ORACLE_HOME/bin
到環境變量.bash_profile並source,或者建立一個link文件:
[oracle@zlm gg11]$ ln -s /u01/app/oracle/product/11.2.0/db_1/lib/libnnz11.so -
/u01/app/oracle/product/11.2.0/db_1/lib/libnnz10.so
1.4 建立OGG專用目錄subdirs
GGSCI (zlm) 1> create subdirs
Creating subdirectories under current directory /u01/app/oracle/gg11
Parameter files /u01/app/oracle/gg11/dirprm: already exists
Report files /u01/app/oracle/gg11/dirrpt: created
Checkpoint files /u01/app/oracle/gg11/dirchk: created
Process status files /u01/app/oracle/gg11/dirpcs: created
SQL script files /u01/app/oracle/gg11/dirsql: created
Database definitions files /u01/app/oracle/gg11/dirdef: created
Extract data files /u01/app/oracle/gg11/dirdat: created
Temporary files /u01/app/oracle/gg11/dirtmp: created
Stdout files /u01/app/oracle/gg11/dirout: created
1.5 開啓歸檔模式、強制日誌、附加日誌
查看v$database看這3個參數是否已開啓,使用OGG必須是開啓狀態
SQL> select LOG_MODE, SUPPLEMENTAL_LOG_DATA_MIN,FORCE_LOGGING from v$database;
LOG_MODE SUPPLEME FOR
------------ -------- ---
ARCHIVELOG YES YES
各參數開啓方法:
--archivelog
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open;
--force logging
SQL> alter database force logging;
--supplemental log data
SQL> alter database add supplemental log data;
1.6 關閉數據庫的recyclebin(10gDDL必須,11gDDL可選)
SQL> alter system set recyclebin=off scope=spfile; --同步DDL要求關閉10g中的回收站特性
1.7 建立複製用戶ogg並授予權限
SQL> create user ogg identified by ogg default tablespace users temporary tablespace temp;
SQL> grant connect,resource,unlimited tablespace to ogg;
1.8 建立測試用戶sender並授予權限
SQL> create user sender identified by sender default tablespace users temporary tablespace temp;
SQL> grant connect,resource,unlimited tablespace to sender;
1.9 配置複製的DDL支持(必須SYSDBA登陸執行)
SQL> grant execute on utl_file to ogg;
SQL> @$GGHOME/marker_setup.sql; --創建一個DDL標記表
SQL> @$GGHOME/ddl_setup.sql; --INITIALSETUP選項運行ddl_setup.sql 將在數據庫中建立捕獲DDL語句的Trigger等必要組件(注意,執行時必須斷開GGSCI鏈接,不然報錯)
SQL> @$GGHOME/role_setup.sql; --創建GGS_GGSUSER_ROLE角色
SQL> grant GGS_GGSUSER_ROLE to ogg; --授予給extract group參數中定義的userid用戶
SQL> @$GGHOME/ddl_enable.sql; --enable ddl捕獲觸發器
注意:下面2個SQL腳本只是爲了提升DDL複製性能,不是必須的
SQL> @?/rdbms/admin/dbmspool --建立DBMS_SHARED_POOL包
SQL> @ddl_pin --經過dbms_shared_pool.keep存儲過程將DDLReplication相關的對象keep在共享池中,以保證這些對象不要reload,提高性能
1.10 目標端重複配置以上1.1-1.9所有內容,至此,ORACLE-ORACLE環境搭建完畢
2、用EXPDP/IMPDP初始化測試數據(僅限ORACLE-ORACLE)
2.1 建立EXPDP/IMPDP使用的directory及其對應的本地目錄
SQL> set lin 200 pages 999
SQL> col owner for a5
SQL> col directory_name for a25
SQL> col directory_path for a75
SQL> select * from dba_directories;
OWNER DIRECTORY_NAME DIRECTORY_PATH
----- ------------------------- ----------------------------------------------------------------------
SYS GGS_DDL_TRACE /u01/app/oracle/diag/rdbms/zlm11g/zlm11g/trace
SYS SUBDIR /u01/app/oracle/product/11.2.0/db_1/demo/schema/order_entry//2002/Sep
SYS SS_OE_XMLDIR /u01/app/oracle/product/11.2.0/db_1/demo/schema/order_entry/
SYS BACKUP /u01/backup
SYS LOG_FILE_DIR /u01/app/oracle/product/11.2.0/db_1/demo/schema/log/
SYS MEDIA_DIR /u01/app/oracle/product/11.2.0/db_1/demo/schema/product_media/
SYS XMLDIR /u01/app/oracle/product/11.2.0/db_1/rdbms/xml
SYS DATA_FILE_DIR /u01/app/oracle/product/11.2.0/db_1/demo/schema/sales_history/
SYS DATA_PUMP_DIR /u01/app/oracle/admin/zlm11g/dpdump/
SYS ORACLE_OCM_CONFIG_DIR /u01/app/oracle/product/11.2.0/db_1/ccr/state
SQL> create directory expdump as '/u01/expdp';
SQL> select * from dba_directories;
OWNER DIRECTORY_NAME DIRECTORY_PATH
----- ------------------------- ----------------------------------------------------------------------
SYS GGS_DDL_TRACE /u01/app/oracle/diag/rdbms/zlm11g/zlm11g/trace
SYS EXPDUMP /u01/expdp
SYS SUBDIR /u01/app/oracle/product/11.2.0/db_1/demo/schema/order_entry//2002/Sep
SYS SS_OE_XMLDIR /u01/app/oracle/product/11.2.0/db_1/demo/schema/order_entry/
SYS BACKUP /u01/backup
SYS LOG_FILE_DIR /u01/app/oracle/product/11.2.0/db_1/demo/schema/log/
SYS MEDIA_DIR /u01/app/oracle/product/11.2.0/db_1/demo/schema/product_media/
SYS XMLDIR /u01/app/oracle/product/11.2.0/db_1/rdbms/xml
SYS DATA_FILE_DIR /u01/app/oracle/product/11.2.0/db_1/demo/schema/sales_history/
SYS DATA_PUMP_DIR /u01/app/oracle/admin/zlm11g/dpdump/
SYS ORACLE_OCM_CONFIG_DIR /u01/app/oracle/product/11.2.0/db_1/ccr/state
[oracle@zlm gg11]$ cd /u01/
[oracle@zlm u01]$ ls
app backup
[oracle@zlm u01]$ mkdir /u01/expdp
[oracle@zlm u01]$ ll
total 16
drwxr-xr-x 4 oracle oinstall 4096 Jul 13 03:12 app
drwxrwxr-x 2 oracle oinstall 4096 Jul 21 20:26 backup
drwxr-xr-x 2 oracle oinstall 4096 Aug 28 22:11 expdp
2.2 登陸sender用戶並建立測試表test
SQL> conn sender/sender
Connected.
SQL> begin
2 for i in 1..3 loop
3 insert into test values(i);
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> select * from test1;
ID
----------
1
2
3
2.3 賦予sender讀寫directory的權限,執行expdp導出測試表test
SQL> grant read,write on directory expdump to sender;
SQL> !
[oracle@zlm ~]$ expdp sender/sender directory=expdump dumpfile=test.dmp logfile=test.log tables=test
[oracle@zlm ~]$ cd /u01/expdp
[oracle@zlm expdp]$ ls
test.dmp test.log
2.4 在目標端建立directory及相應的本地路徑,複製dump文件到目標端
SQL> create directory impdump as ‘/u01/impdp’;
--target
[oracle@zlm2 gg11]$ mkdir /u01/impdp
[oracle@zlm2 gg11]$ ls /u01
app backup impdp
--source
[oracle@zlm expdp]$ scp test.* zlm2:/u01/impdp
oracle@zlm2's password:
test.dmp 100% 92KB 92.0KB/s 00:00
test.log 100% 1011 1.0KB/s 00:00
2.5 目標端賦予recerver用戶權限,執行impdp導入測試表test
SQL> grant read,write on directory impdump to sender;
SQL> !
[oracle@zlm2 ~]$ impdp sender/sender directory=impdump dumpfile=test.dmp tables=test
注意:expdp/impdp必須是在同一個schema下的object,不然不能執行成功,logfile能夠無
SQL> conn sender/sender
Connected.
SQL> select * from test;
ID
----------
1
2
3
此時完成test表的初始化同步,注意:若是非ORACLE-ORACLE方式同步,則只能使用OGG推薦的方式,即配置initial extract來初始化數據,具體能夠參考我以前的一篇blog:
http://blog.csdn.net/aaron8219/article/details/10275431
3、不使用PUMP抽取進程的DML同步參數配置(ORACLE-ORACLE)
3.1 單向複製
3.1.1 建立並配置manager
[ogg@zlm gg11]$ ./ggsci
GGSCI (zlm) 1> info all
GGSCI (zlm) 2> edit params mgr
PORT 7809
ggate (zlm) 3> start manager
Manager started.
3.1.2 配置源端抽取組ext1
GGSCI (zlm) 1> add extract ext1, tranlog, begin now
GGSCI (zlm) 2> add rmttrail ./dirdat/rt, extract ext1
GGSCI (zlm) 3> edit params ext1
extract ext1
userid ogg, password ogg
rmthost zlm2, mgrport 7809
rmttrail ./dirdat/rt
ddl include mapped objname sender.*;
table sender.*;
GGSCI (zlm) 4> info all
3.1.3 配置目標端同步組
3.1.3.1 在目標端添加checkpoint表
[ogg@zlm gg11]$ ./ggsci
GGSCI (zlm2) 1> edit params ./GLOBAL
GGSCHEMA ogg
CHECKPOINTTABLE ogg.ckpt
GGSCI (zlm2) 2> dblogin userid ogg password ogg
GGSCI (zlm2) 3> add checkpointtable ogg.ckpt
3.1.3.2 建立同步組rep1
GGSCI (zlm2) 4> add replicat rep1, exttrail ./dirdat/rt, checkpointtable ogg.ckpt
GGSCI (zlm2) 5> edit params rep1
replicat rep1
ASSUMETARGETDEFS
userid ogg,password ogg
reperror default,discard
discardfile ./dirrpt/rep1.dsc, append, megabytes 5
DDL
map sender.*, target sender.*;
3.1.4 源端開啓抽取組ext1,目標端開啓同步組rep1
--source
GGSCI (zlm) 1> start mgr
GGSCI (zlm) 2> start extract ext1
GGSCI (zlm) 3> info all
--target
GGSCI (zlm2) 1> start mgr
GGSCI (zlm2) 2> start replicat rep1
GGSCI (zlm2) 3> info all
3.1.5 測試DML同步
3.1.5.1 insert
--source
SQL> select * from test
2 /
ID
----------
1
2
3
SQL> insert into test values(4);
1 row created.
SQL> commit;
Commit complete.
--target
SQL> select * from test;
ID
----------
1
2
3
4
注意:能夠順利同步,可是查看ext1和rep1的run time messages,都報了以下的錯誤:
WARNING OGG-00869 No unique key is defined for table 'TEST'. All viable columns will b
e used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Using the following key columns for source table SENDER.TEST: ID.
該表沒有主鍵,使用KEYCOLS代替,查詢官方說明以下:
OGG-00869: {0}
Cause: The specified database error occurred, but can be ignored.
Action: Contact Oracle Support only if a problem persists.
因爲這只是個警告,何況對實際的應用也沒什麼影響,是能夠忽略掉的。
3.1.5.2 update
(略)...
3.1.5.3 delete
(略)...
3.1.6 測試DDL同步(可選)
測試DDL須要以前作過1.8步驟的所有配置(綠色部分),並在相應參數中添加過相應DDL須要使用的參數(綠色部分)
3.1.6.1 create table
--source
SQL> create table test2 as select * from test;
Table created.
--target
SQL> select * from test2;
ID
----------
1
2
3
5 rows selected.
3.1.6.2 alter table
--source
SQL> alter table test2 add (name varchar(10));
Table altered.
--target
SQL> desc test2;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER
NAME VARCHAR2(10)
3.1.6.3 tuncate table
--source
SQL> truncate table test2;
Table truncated.
--target
SQL> select * from test2;
no rows selected
3.1.6.4 drop table
--source
SQL> drop table test2;
Table dropped.
--target
SQL> desc test2
ERROR:
ORA-04043: object test2 does not exist
至此,不設置本地trail和pump抽取進程的DML,DDL均可以順利複製到目標端
3.2 雙向複製
雙向複製,其實就是再配置一條目標端到源端的複製通道,分別在源端和目的端各配置一個extract和replicat進程就能夠了
3.2.1 配置源端抽取組ext1
GGSCI (zlm2) 1> add extract ext1, tranlog, begin now
GGSCI (zlm2) 2> add rmttrail ./dirdat/rt, extract ext1
GGSCI (zlm2) 3> edit params ext1
extract ext1
userid ogg, password ogg
rmthost zlm1, mgrport 7809 --注意主機名要修改一下,別的參數和以前的一致就能夠了
rmttrail ./dirdat/rt
ddl include mapped objname sender.*;
table sender.*;
GGSCI (zlm2) 4> info all
3.2.2 配置目標端同步組
3.2.2.1 在目標端添加checkpoint表
[ogg@zlm gg11]$ ./ggsci
GGSCI (zlm) 1> edit params ./GLOBAL
GGSCHEMA ogg --DDL同步必須指定,DML同步不須要
CHECKPOINTTABLE ogg.ckpt
GGSCI (zlm) 2> dblogin userid ogg password ogg
GGSCI (zlm) 3> add checkpointtable ogg.ckpt
3.2.2.2 建立同步組rep1
GGSCI (zlm) 4> add replicat rep1, exttrail ./dirdat/rt, checkpointtable ogg.ckpt
GGSCI (zlm) 5> edit params rep1
replicat rep1
ASSUMETARGETDEFS
userid ogg,password ogg
reperror default,discard
discardfile ./dirrpt/rep1.dsc, append, megabytes 5
DDL
map sender.*, target sender.*;
3.2.3 源端(原目標端)開啓抽取組ext1,目標端(原源端)開啓同步組rep1
--source
GGSCI (zlm2) 1> start mgr
GGSCI (zlm2) 2> start extract ext1
GGSCI (zlm2) 3> info all
--target
GGSCI (zlm) 1> start mgr
GGSCI (zlm) 2> start replicat rep1
GGSCI (zlm) 3> info all
具體測試內容和以前配置的單向複製同樣,步驟略,DML,DDL都順利複製到目標端,和以前同樣,第一次同步的時候會比較慢,以後就快了,多是第一次同步須要建立文件的緣故。另外,這裏要特別注意,此時由於配置了雙向複製,當兩邊各自的ext1和rep1進程都是running狀態,若是此時源端和目標端對同一個表進行DML操做,如insert一條記錄,那麼這條記錄會不斷地在兩端來回複製,永不停歇,以下所示:
SQL> insert into test values(6);
1 row created.
SQL> select *from test;
ID
----------
1
2
3
4
5
6
6
6
6
6
這條插入id=6的數據就會不斷地插入test表,要解決這個問題,就須要在兩端的任意一個extract進程ext1裏添加一條TRANLOGOPTIONS EXCLUDEUSER ogg就能夠了
4、使用PUMP抽取進程的單向複製(ORACLE-ORACLE)
4.1 添加本地trail路徑,修改源端extract抽取組ext1參數
GGSCI (zlm) 1> add extract ext1,tranlog, begin now
GGSCI (zlm) 2> add exttrail ./dirdat/lt,extract ext1
GGSCI (zlm) 3> edit params ext1
extract ext1
userid ogg, password ogg
--rmthost zlm2, mgrport 7809
--rmttrail ./dirdat/rt
exttrail ./dirdat/lt
ddl include mapped objname sender.*;
table sender.*;
註釋掉2行和遠程鏈接有關的參數,再添加一行本地trail路徑便可
4.2 添加pump抽取組epp1
GGSCI (zlm) 1> add extract epp1,exttrailsource ./dirdat/lt
GGSCI (zlm) 2> add rmttrail ./dirdata/rt,extract epp1
GGSCI (zlm) 3> edit params epp1
extract epp1
userid ogg,password ogg
rmthost zlm2, mgrport 7809
rmttrail ./dirdat/rt
ddl include mapped objname sender.*;
table sender.*;
至關於把原來配置在ext1裏的遠程配置參數搬過來了,由於如今是經過pump與遠端鏈接,
replicat複製組rep1參數不用修改,直接使用就能夠
4.2 DML和DDL測試(參考3.1.5和3.1.6的步驟,方法一致)
(略)…
注意:測試同步的時候要多開啓一個pump進程,即源端運行ext1,epp1
5、異構數據庫之間的單向複製(ORACLE-MYSQL)
5.1下載並安裝介質
OGG FOR MYSQL:
官網連接:https://edelivery.oracle.com/EPD/Download/get_form
介質名稱:Oracle GoldenGate V11.1.1.1.1 for MySQL 5.x on Linux x86-64
MYSQL DATABASE:
官網連接:https://edelivery.oracle.com/EPD/Search/handle_go
介質名稱:MySQL Database 5.6.13 RPM for Oracle Linux / RHEL 5 x86 (64bit)
5.1.1目標端安裝OGG軟件並配置環境
由於MYSQL默認是以root用戶登陸並使用的,因此只要配置root的環境變量就能夠了
在root用戶的.bash_profile文件中添加如下內容:
export GGHOME=/ggmysql
export PATH=$PATH:$GGHOME
拷貝OGG FOR MYSQL介質到/rpm目錄下並解壓縮,而後再一次解壓縮到/ggmysql
[root@zlm2 ~]# cd /rpm
[root@zlm2 rpm]# ls
V27808-01.zip
[root@zlm2 rpm]# unzip V27808-01.zip
Archive: V27808-01.zip
inflating: ggs_Linux_x64_MySQL_64bit.tar
inflating: OGG_WinUnix_Rel_Notes_11.1.1.1.1.pdf
inflating: Oracle_GoldenGate_11.1.1.1_README.txt
[root@zlm2 rpm]# ls
ggs_Linux_x64_MySQL_64bit.tar Oracle_GoldenGate_11.1.1.1_README.txt
OGG_WinUnix_Rel_Notes_11.1.1.1.1.pdf V27808-01.zip
[root@zlm2 rpm]# mkdir /ggmysql
[root@zlm2 rpm]# cd /ggmysql
[root@zlm2 ggmysql]# tar -xvf /rpm/ggs_Linux_x86_MySQL_32bit.tar
(略)...
進入OGG界面,添加OGG目錄
[root@zlm2 ggmysql]# ./ggsci
GGSCI (zlm2) 1> create subdirs
5.1.2 目標端安裝配置MYSQL數據庫軟件
把從官網下載的MYSQL數據庫軟件也拷貝到/rpm下並解壓
[root@zlm2 rpm]# ls
[root@zlm2 rpm]# ls
ggs_Linux_x64_MySQL_64bit.tar V27808-01.zip
OGG_WinUnix_Rel_Notes_11.1.1.1.1.pdf V39097-01.zip
Oracle_GoldenGate_11.1.1.1_README.txt
[root@zlm2 rpm]# unzip V39097-01.zip
Archive: V39097-01.zip
extracting: MySQL-shared-compat-advanced-5.6.13-1.rhel5.x86_64.rpm
extracting: MySQL-devel-advanced-5.6.13-1.rhel5.x86_64.rpm
extracting: MySQL-embedded-advanced-5.6.13-1.rhel5.x86_64.rpm
extracting: MySQL-shared-advanced-5.6.13-1.rhel5.x86_64.rpm
extracting: MySQL-server-advanced-5.6.13-1.rhel5.x86_64.rpm
extracting: MySQL-test-advanced-5.6.13-1.rhel5.x86_64.rpm
extracting: MySQL-client-advanced-5.6.13-1.rhel5.x86_64.rpm
extracting: README.txt
MYSQL數據庫軟件是一個rpm包,直接以root執行rpm命令進行安裝
若是提示libaio.so.1依賴包沒有安裝的錯誤,就要先安裝依賴包libaio
配置本地yum並執行:yum install libaio,或者直接用rpm包安裝
[root@zlm2 rpm]# rpm -ivh MySQL-server-advanced-5.6.13-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-server-advanced ########################################### [100%]
2013-08-30 22:46:21 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-08-30 22:46:21 5633 [Note] InnoDB: The InnoDB memory heap is disabled
2013-08-30 22:46:21 5633 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2013-08-30 22:46:21 5633 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-08-30 22:46:21 5633 [Note] InnoDB: Using Linux native AIO
2013-08-30 22:46:21 5633 [Note] InnoDB: Not using CPU crc32 instructions
/usr/sbin/mysqld: Can't create/write to file '/tmp/ibgnuRhJ' (Errcode: 13 - Permission denied)
2013-08-30 22:46:21 7fa1cc42c6f0 InnoDB: Error: unable to create temporary file; errno: 13
2013-08-30 22:46:21 5633 [ERROR] Plugin 'InnoDB' init function returned error.
2013-08-30 22:46:21 5633 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2013-08-30 22:46:21 5633 [ERROR] Unknown/unsupported storage engine: InnoDB
2013-08-30 22:46:21 5633 [ERROR] Aborting
2013-08-30 22:46:21 5633 [Note] Binlog end
2013-08-30 22:46:21 5633 [Note] /usr/sbin/mysqld: Shutdown complete
顯示完以上信息後就停住了,跳回了root的shell界面,查看了上面提示的內容,
出現幾個報錯,第一次裝MYSQL,不太明白是什麼意思,網上查了一下說是須要配置my.cnf參數,直接在my.cnf裏的mysqld下加一行explicit_defaults_for_timestamp
http://bbs.csdn.net/topics/390369836?page=1#post-393710642
可是我以爲應該不是這個問題,如今軟件確定是尚未裝好,查看了一下,相關的目錄和配置文件都沒有建立,多是官網這個最新版server-advanced-5.6.13包兼容性有點問題,網上查了一下,也說最好別下官網最新版的MYSQL數據庫安裝包
因而去MYSQL官網下載MySQL Community Server最新版
官方連接:http://dev.mysql.com/downloads/mirror.php?id=414018
介質名稱:MySQL-server-5.6.13-1.rhel5.x86_64.rpm
官方連接:http://dev.mysql.com/downloads/mirror.php?id=413959
介質名稱:MySQL-client-5.6.13-1.rhel5.x86_64.rpm
把新下載的RPM拷貝到/rpm目錄下,從新安裝MYSQL,可是此時又發現一個問題
[root@zlm2 rpm]# rpm -ivh MySQL-server-5.6.13-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
file /usr/bin/innochecksum from install of MySQL-server-5.6.13-1.rhel5.x86_64 conflicts with file from package MySQL-server-advanced-5.6.13-1.rhel5.x86_64
file /usr/bin/my_print_defaults from install of MySQL-server-5.6.13-1.rhel5.x86_64 conflicts with file from package MySQL-server-advanced-5.6.13-1.rhel5.x86_64
(略)...
因爲以前的server-advacned包沒有徹底正確安裝,如今再安裝這個包提示和以前的包有衝突,沒法繼續安裝,因而想到先卸載一下以前安裝的包:
[root@zlm2 rpm]# rpm -ev MySQL-server-advanced-5.6.13-1.rhel5.x86_64.rpm
error: package MySQL-server-advanced-5.6.13-1.rhel5.x86_64.rpm is not installed
提示以前的server-advanced包並無安裝,也沒法卸載,如今不知道如何清除以前rpm的安裝殘留信息,因此換了一臺以前裝的Oracle ASM單實例數據庫的主機,進行安裝:
SQL-server-5.6.13-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
2013-08-31 13:16:17 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-08-31 13:16:17 4462 [Note] InnoDB: The InnoDB memory heap is disabled
2013-08-31 13:16:17 4462 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2013-08-31 13:16:17 4462 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-08-31 13:16:17 4462 [Note] InnoDB: Using Linux native AIO
2013-08-31 13:16:17 4462 [Note] InnoDB: Not using CPU crc32 instructions
2013-08-31 13:16:17 4462 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2013-08-31 13:16:17 4462 [Note] InnoDB: Completed initialization of buffer pool
2013-08-31 13:16:17 4462 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2013-08-31 13:16:17 4462 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2013-08-31 13:16:17 4462 [Note] InnoDB: Database physically writes the file full: wait...
2013-08-31 13:16:18 4462 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2013-08-31 13:16:20 4462 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2013-08-31 13:16:21 4462 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2013-08-31 13:16:21 4462 [Warning] InnoDB: New log files created, LSN=45781
2013-08-31 13:16:21 4462 [Note] InnoDB: Doublewrite buffer not found: creating new
2013-08-31 13:16:21 4462 [Note] InnoDB: Doublewrite buffer created
2013-08-31 13:16:21 4462 [Note] InnoDB: 128 rollback segment(s) are active.
2013-08-31 13:16:21 4462 [Warning] InnoDB: Creating foreign key constraint system tables.
2013-08-31 13:16:21 4462 [Note] InnoDB: Foreign key constraint system tables created
2013-08-31 13:16:21 4462 [Note] InnoDB: Creating tablespace and datafile system tables.
2013-08-31 13:16:21 4462 [Note] InnoDB: Tablespace and datafile system tables created.
2013-08-31 13:16:21 4462 [Note] InnoDB: Waiting for purge to start
2013-08-31 13:16:21 4462 [Note] InnoDB: 5.6.13 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2013-08-31 13:16:22 4462 [Note] Binlog end
2013-08-31 13:16:22 4462 [Note] InnoDB: FTS optimize thread exiting.
2013-08-31 13:16:22 4462 [Note] InnoDB: Starting shutdown...
2013-08-31 13:16:23 4462 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2013-08-31 13:16:23 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-08-31 13:16:23 4486 [Note] InnoDB: The InnoDB memory heap is disabled
2013-08-31 13:16:23 4486 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2013-08-31 13:16:23 4486 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-08-31 13:16:23 4486 [Note] InnoDB: Using Linux native AIO
2013-08-31 13:16:23 4486 [Note] InnoDB: Not using CPU crc32 instructions
2013-08-31 13:16:23 4486 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2013-08-31 13:16:23 4486 [Note] InnoDB: Completed initialization of buffer pool
2013-08-31 13:16:23 4486 [Note] InnoDB: Highest supported file format is Barracuda.
2013-08-31 13:16:23 4486 [Note] InnoDB: 128 rollback segment(s) are active.
2013-08-31 13:16:23 4486 [Note] InnoDB: Waiting for purge to start
2013-08-31 13:16:23 4486 [Note] InnoDB: 5.6.13 started; log sequence number 1625977
2013-08-31 13:16:24 4486 [Note] Binlog end
2013-08-31 13:16:24 4486 [Note] InnoDB: FTS optimize thread exiting.
2013-08-31 13:16:24 4486 [Note] InnoDB: Starting shutdown...
2013-08-31 13:16:25 4486 [Note] InnoDB: Shutdown completed; log sequence number 1625987
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.
You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
[root@dg1 rpm]#
[root@dg1 ~]# rpm -qa|grep -i mysql
MySQL-server-5.6.13-1.rhel5
此次安裝很順利地就完成了,以前安裝失敗的主機和這臺ASM單實例主機用的是OEL5.7的系統,因此排除了系統問題,確定是以前的軟件兼容性問題,繼續安裝client軟件
[root@dg1 rpm]# rpm -ivh MySQL-client-5.6.13-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
至此,MYSQL順利安裝完畢!
5.1.3 啓動MYSQL
[root@dg1 rpm]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
報錯了,可使用下面的命令啓動:
service mysql start或/etc/init.d/mysql start或/etc/rc.d/init.d/mysql start
[root@dg1 rpm]# service mysql start
Starting MySQL...... [ OK ]
[root@dg1 rpm]#
5.1.4 登陸MYSQL
[root@dg1 rpm]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@dg1 rpm]#
該錯誤提示不用密碼是沒法訪問的,注意此時用mysql -u root -p的方式也是沒法登陸的,由於此時沒有正確的root密碼,必須先強制修改root密碼,解決方法以下:
[root@dg1 rpm]# /etc/init.d/mysql stop
Shutting down MySQL.. [ OK ]
[root@dg1 rpm]# /usr/bin/mysqld_safe --skip-grant-tables
130831 14:32:39 mysqld_safe Logging to '/var/lib/mysql/dg1.err'.
130831 14:32:39 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
另外再開一個SSH後執行:
[root@dg1 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=password("123456") where user="root";
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
直接關閉新開的SSH,或者執行pkill -KILL -t pts/0 可將pts爲0的**用戶(以前運行mysqld_safe的用戶窗口)強制踢出
而後在原來的SSH,執行Ctrl+Z退出skip-grant-tables模式
[1]+ Stopped /usr/bin/mysqld_safe --skip-grant-tables
[root@dg1 rpm]#
正常啓動 MySQL:/etc/init.d/mysql start (service mysqld start)
此時再使用密碼方式登陸:
[root@dg1 rpm]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.13
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
以後有人提醒我,MYSQL安裝完之後默認密碼爲空,也就是說,若是不進行強制修改密碼方式,直接執行#mysql -u root -p也是能夠進入系統的,當提示輸入密碼時直接回車就能夠,這個我尚未驗證過,若是是真的話,那我就繞圈子了,呵呵
若是已經登錄進系統,想修改某用戶的密碼,能夠執行以下命令:
[root@dg1 ~]# /usr/bin/mysqladmin -u root password 123456
5.1.5 操做數據庫
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
以前已經用安全模式給MYSQL從新修改了密碼,也用密碼登錄了,可是仍然提示須要密碼
查閱官方文檔:http://dev.mysql.com/doc/refman/5.6/en/alter-user.html
原來還要從新執行一個操做,再設置一下密碼:
mysql> set password=password('123456');
Query OK, 0 rows affected (0.03 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use test
Database changed
mysql> show tables;
Empty set (0.00 sec)
5.1.6 設置開機自啓動(可選)
能夠在/etc/rc.local文件中添加如下MYSQL自啓動命令:
/etc/init.d/mysql start
另外也可使用chkconfig命令配置自啓動:
# chkconfig --list | grep mysql
# chkconfig --add mysql
設置完重啓系統後,使用netstat-nat命令能夠看到MYSQL的3306端口
#netstat-nat|grep 3306
5.1.7 MYSQL幾個重要目錄說明
(1)數據庫目錄
/var/lib/mysql/
(2)配置文件
/usr/share/mysql(mysql.server命令及配置文件)
(3)相關命令
/usr/bin(mysqladmin mysqldump等命令)
(4)啓動腳本
/etc/rc.d/init.d/(啓動腳本文件mysql的目錄)
若想查看MySQL安裝到哪一個目錄,可以使用「whereis mysql」命令查看
官方說明:
Table 2.9. MySQL Installation Layout for Linux RPM Packages
Directory |
Contents of Directory |
/usr/bin |
Client programs and scripts |
/usr/sbin |
The mysqld server |
/var/lib/mysql |
Log files, databases |
/usr/share/info |
Manual in Info format |
/usr/share/man |
Unix manual pages |
/usr/include/mysql |
Include (header) files |
/usr/lib/mysql |
Libraries |
/usr/share/mysql |
Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation |
/usr/share/sql-bench |
Benchmarks |
5.2 源端建立defgen文件並配置
異構數據庫之間同步數據必須利用結構轉換文件
GGSCI (zlm) 1> edit params defgen
defsfile ./dirdef/oratomy.def,purge
userid ogg, password ogg
table sender.*;
[oracle@zlm gg11] $ ./defgen paramfile ./dirprm/defgen.prm
執行前必須先啓動oracle數據庫,不然會報:
ERROR OGG-00664 OCI Error beginning session (status = 1034-ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory).
ERROR OGG-01668 PROCESS ABENDING.
再執行一次也會報錯:
ERROR OGG-00037 DEFSFILE file ./dirdef/oratomy.def already exists.
ERROR OGG-01668 PROCESS ABENDING.
此時應該先刪除原先的那個def文件,再執行一次,直到出現:
Definitions generated for 2 tables in ./dirdef/oratomy.def
這裏這條命令的做用就是生成oratomy.def這個異構數據庫轉換文件
將生成的該文件拷貝到目標端相同位置:
[root@zlm ~]# scp /u01/app/oracle/gg11/dirdef/oratomy.def dg1:/ggmysql/dirdef
The authenticity of host 'dg1 (192.168.1.99)' can't be established.
RSA key fingerprint is e4:1f:12:e6:63:13:3a:2a:ad:52:e3:4a:68:b6:33:e0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'dg1,192.168.1.99' (RSA) to the list of known hosts.
root@dg1's password:
oratomy.def 100% 1079 1.1KB/s 00:00
[root@zlm ~]#
5.3 一致性抽取源端數據到目標端
因爲是異構數據庫之間複製數據,初始化不能採用rman、dexpdp/impdp、傳輸表空間等oracle的方式來完成,這裏選用Goldengate推薦的的初始化方式完成
5.3.1 源端增長用戶對象的trandata日誌
GGSCI (zlm) 1> dblogin userid ogg,password ogg
GGSCI (zlm) 2> add trandata sender.*
5.3.2 源端配置初始化抽取組eini
GGSCI (zlm) 1> add extract eini,sourceistable
GGSCI (zlm) 2> edit params eini
extract eini
userid ogg,password ogg
rmthost dg1,mgrport 7809
rmttask replicat,group rini
table sender.*;
5.3.3 目標端配置複製組rini
GGSCI (dg1) 1> add replicat rini,specialrun
GGSCI (dg1) 2> edit params rini
replicat rini
sourcedb test userid root,password 123456
sourcedefs ./dirdef/oratomy.def
discardfile ./dirrpt/rini.dsc,append,megabytes 5
map sender.*, target test.*;
5.3.4 運行源端manager和extract抽取組進程
GGSCI (zlm) 1> start mgr
GGSCI (zlm) 2> start eini
5.3.5 運行目標端manager進程
GGSCI (zlm2) 1> start mgr
注意:當使用OGG推薦方式初始化數據時,目標端replicat複製組進程會自動運行,不用手動啓動,就能夠完成一次性抽取
當啓動進程後,源端ggserr.log裏提示有錯誤:
2013-08-31 17:43:13 WARNING OGG-01194 Oracle GoldenGate Capture for Oracle, eini.prm: EXTRACT task RINI abended : Problem at line 27. Expecting file, table, or record definition.
2013-08-31 17:43:13 ERROR OGG-01203 Oracle GoldenGate Capture for Oracle, eini.prm: EXTRACT abending.
2013-08-31 17:43:13 ERROR OGG-01668 Oracle GoldenGate Capture for Oracle, eini.prm: PROCESS ABENDING.
目標端的ggserr.log裏也有一樣的提示:
2013-08-31 17:43:12 INFO OGG-00995 Oracle GoldenGate Delivery for MySQL, rini.prm: REPLICAT RINI starting.
2013-08-31 17:43:12 ERROR OGG-00303 Oracle GoldenGate Delivery for MySQL, rini.prm: Problem at line 27. Expecting file, table, or record definition.
2013-08-31 17:43:17 ERROR OGG-01668 Oracle GoldenGate Delivery for MySQL, rini.prm: PROCESS ABENDING
從該提示看來,應該是def文件的問題,可是以前已經建立並複製到目標庫了,應該沒有什麼問題啊,查看了MOS上的文章才知道,原來這是因爲目標端的OGG軟件版本比源端版本低的緣故:
Replicat abend with ERROR OGG-00303 Problem at line xx. Expecting file, table, or record definition. (Doc ID 1455370.1)
In OGG 11.2, there is a new parameter NOEXTATTR. This is used in DEFGEN. When the OGG version in a target site is lower than the source site, defgen needs to use parameter NOEXTATTR to generate a sourcedef file which target site can read . If using a sourcedef file generated without NOEXTATTR, a replicat will abend with error 00303.
So there are two ways to get around the issue:
1. Use a defgen paramfile with NOEXTATTR option, or
2. Generate definition file with the same OGG version as the OGG target site version.
此處採用辦法1,添加NOEXTATTR參數選項,從新生成def文件,並複製到目標端,注意先把原來的def文件刪除再添加。在用了新的def文件以後,以前的問題已經解決
重啓兩端mgr和源端的eini後,源端eini的report沒有任何錯誤提示,但目標端rini的report報了一個錯誤:
ERROR OGG-00770 Failed to connect to MySQL database engine for HOST localhost, DATABASE test, USER root, PORT 3306.
ERROR OGG-01668 PROCESS ABENDING.
查看源端eini的report繼續報錯:
WARNING OGG-01194 Oracle GoldenGate Capture for Oracle, eini.prm: EXTRACT task RINI abended : Failed to connect to MySQL database engine for HOST localhost, DATABASE test, USER root, PORT 3306.
查看目標端並無生成rini的report,由於在eini先abending了
GGSCI (dg1) 5> view report rini
ERROR: REPORT file RINI does not exist.
直接登陸也是報錯:
GGSCI (dg1) 9> dblogin sourcedb test,userid root,password 123456
WARNING OGG-00769 MySQL Login failed: . SQL error (2002). Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2).
解決辦法:
修改/etc/my.cnf文件,將server和client的socket修改成:/tmp/mysql.sock
重啓mysql:/etc/init.d/mysql stop/start
GGSCI (dg1) 3> dblogin sourcedb test,userid root,password 123456
Successfully logged into database.
GGSCI (dg1) 9> dblogin sourcedb test@localhost.localdomain,userid root,password 123456
Successfully logged into database.
這兩種均可以登陸方式登陸都成功
可是這樣改了之後,又碰到一個問題,就是沒法登陸mysql了
[root@dg1 ggmysql]# service mysql start
Starting MySQL [ OK ]
[root@dg1 ggmysql]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
因而只好再改回socket爲註釋狀態,彷佛碰到了一個無解的狀態
MYSQL的SOCKET問題還真是麻煩,把socket文件從新連接一下:
[root@dg1 ~]# locate mysql.sock
/var/lib/mysql/mysql.sock
[root@dg1 ~]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
或者定義一下用戶的MYSQL_UNIX_PORT變量,指向MySQL數據庫文件的目錄便可,即:
export MYSQL_UNIX_PORT=/var/lib/mysql/mysql.sock
GGSCI (dg1) 1> dblogin sourcedb test userid root,password 123456
Successfully logged into database.
接着再啓動源端、目標端進程,又出現錯誤:
WARNING OGG-01223 TCP/IP error 111 (Connection refused).
WARNING OGG-01223 TCP/IP error 104 (Connection reset by peer).
WARNING OGG-01223 TCP/IP error 107 (Transport endpoint is not connected).
緣由是必須等Target 端的GG進程(mrg進程)啓動之後才能啓動
以前的問題都已經逐步解決掉了,如今又碰到一個報錯:
ERROR OGG-01389 File header failed to parse tokens. File
INITIALDATALOAD, last offset 815, data:
Google到一篇老外寫的關於這個問題的解決方法:
解決方法與MOS上的文章差很少:
OGG v11.1.1.0.0 JMS Adapter reading OGG v11.2.1.x trails (文檔 ID 1477046.1)
Cause:
JMS EXTRACT v11.1.1.0.0 user-exit is compatible with v11.2.x EXTRACT but there are certain configuration steps you must follow for backwards compatibility.
Solution:
1. Generate the sourcedefs with the NOEXTATTR option to create a backwards compatible sourcedefs file:
os> DEFGEN paramfile …., NOEXTATTR
2. Use FORMAT RELEASE 9.5 in the source EXTRACT and any EXTRACT PUMP to write trails that are in v9.5 format
exttrail /u01/app/goldengate/dirdat/ae,format release 9.5
rmttrail /u01/app/goldengate/dirdat/ae, format release 9.5
See KM Doc ID 1395761.1.
3. The EXTRACT used to execute the v11.1.1.0.x Adapter must be OGG v11.1.x. Do not use v11.2 EXTRACT to execute v11.1.1.x Adapter.
You can use FORMAT RELEASE 11.1 if using JMS Adapter v11.1.1.0.10+ with properties value of "gg.brokentrail=true"
這裏都提到了在用到trail文件時,經過添加release version xx.x 來下降源端的trail文件版本,可是對於初始化數據時碰到的這個狀況,並無給出解決方法
因爲OGG FOR MYSQL目前最高版本官網只提供到11.1,看來要作初始化的ORACLE->MYSQL只有下降源端OGG版本才能解決了
無奈只能從新去官網下載11.1版本的OGG
官網連接:https://edelivery.oracle.com/EPD/Search/handle_go
介質名稱:Oracle GoldenGate V11.1.1.1.2 for Oracle 11g on Linux x86-64
安裝過程參考以前11.2版本的步驟,此處略
從新運行目標端、源端相應進程後,查看eini的report信息:
Database Language and Character Set:
NLS_LANG environment variable specified has invalid format, default value will be used.
NLS_LANG environment variable not set, using default value
AMERICAN_AMERICA.US7ASCII.
NLS_LANGUAGE = "AMERICAN"
NLS_TERRITORY = "AMERICA"
NLS_CHARACTERSET = "AL32UTF8"
Warning: your NLS_LANG setting does not match database server language setting.
Please refer to user manual for more information.
提示環境變量字符集與數據庫字符集不一致
在源端環境變量中添加:export NLS_LANG=’AMERICAN_AMERICA.AL32UTF8’
WARNING OGG-00869 Oracle GoldenGate Capture for Oracle, eini.prm: No unique key is defined for table TEST2. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
字符集的問題解決了,可是從ggserr.log中的提示看來,測試表尚未惟一鍵定義,難道這是形成不能同步的緣由嗎?來測試一下,給測試表加上主鍵約束:
SQL> alter table test2 add constraint pk_test2 primary key(id);
注意:由於增長了主鍵,表結構已經變化了,要從新生成def文件並複製到目標端
作完以上步驟之後,目標端的rini的report依然報錯:No records were replicated.
說明沒有主鍵並非致使不一樣步的緣由,應該是在ORACLE->MYSQL的時候,表名沒有匹配,作了一個默認的轉換,由於我在eini的report中發現了這麼一條:
TABLEWildcard resolved (entry SENDER.*):
table SENDER.TEST2;
明明配置的是table setender.*,如今變成通過通配符轉換之後,變成大寫的了,那目標端的rini參數裏是否也要改寫成大寫才行呢?
修改目標端rini參數,注意:必定要這麼改!!!
map SENDER..TEST2,target test.test2;
關於這個map target轉換參數的總結:
1、因爲MYSQL的數據庫是大小寫敏感的,不像ORACLE數據庫那樣會自動進行轉換(建立時用的小寫表名,在OGG傳遞的時候用大寫的進行轉換),這裏因爲在源端的eini進程作了一個轉換,因此在目標端的replicat參數中必定要寫成同樣的,不然就是No recoerds were replicated的提示
2、這裏還要注意一個問題,taget和以前的「,」之間必需要寫一個空格,不然也會提示No recoerds were replicated,而且會報一個錯:
ERROR OGG-00212 Invalid option for MAP: test.test2.
發現這個錯誤不要誤覺得是teest.test2名字寫錯了,只是由於少了一個空格,在目標端rini參數中修改以上2處錯誤之後,提示已經正常同步了,困擾我1天ORACLE->MYSQL的初始化問題終於獲得解決:
***********************************************************************
** Run Time Messages **
***********************************************************************
MAP resolved (entry SENDER.TEST2):
map SENDER.TEST2, target test.test2;
Using following columns in default map by name:
id
Using the following key columns for target table test.test2: id.
***********************************************************************
* ** Run Time Statistics ** *
***********************************************************************
Report at 2013-09-01 11:14:01 (activity since 2013-09-01 11:13:56)
From Table SENDER.TEST2 to test.test2:
# inserts: 3
# updates: 0
# deletes: 0
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test2 |
+----------------+
1 row in set (0.00 sec)
mysql> select * from test2;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.06 sec)
源端以前創建了一張只有一個字段(id ini)和3條記錄的表,如今已經利用OGG初始化方式同步到目標端,初始化測試完畢!
5.4 源端配置extract抽取組eotomy
GGSCI (zlm) 1> add extract eotomy,tranlog,begin now
GGSCI (zlm) 2> add exttrail ./dirdat/lm,extract eotomy
GGSCI (zlm) 3> edit params eotomy
extract eotomy
userid ogg, password ogg
--defsfile ./dirdef/oratomy.def
exttrail ./dirdat/lm
table sender.*;
5.5 源端配置pump抽取組potomy
GGSCI (zlm) 1> add extract potomy,exttrailsource ./dirdat/lm
GGSCI (zlm) 2> add rmttrail ./dirdat/rm,extract potomy
GGSCI (zlm) 3> edit params potomy
extract potomy
userid ogg,password ogg
rmthost dg1, mgrport 7809
rmttrail ./dirdat/rm
5.6 配置./GLOBALS參數並建立checkpointtable
GGSCI (dg1) 1> edit params ./GLOABLS
checkpointtable test.chkpt
GGSCI (dg1) 2> add checkpointtable test.chkpt
驗證一下:
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| chkpt |
| test2 |
+----------------+
2 rows in set (0.00 sec)
5.7 目標端配置replicat複製組rmysql
GGSCI (zlm2) 1> add replicat rotomy,exttrail ./dirdat/rm,checkpointtable test.chkpt
GGSCI (zlm2) 2> edit params rotomy
replicat rotomy
sourcedefs ./dirdef/oratomy.def --同構複製就替換成這個參數assumetargetdefs
--dboptions host dg1,connectionport 3306 --這句能夠缺省,默認以3306端口鏈接MYSQL
sourcedb test userid root,password 123456
reperror default,discard
discardfile ./dirrpt/rotomy.dsc,append,megabytes 5
map SENDER.TEST2, target test.test2;
5.8 開始DML同步測試
首先保證源和目標端的mgr進程已經開啓,而後依次啓動源端的eotomy、potomy抽取組和目標端的rotomy同步組
5.8.1 INSERT
SQL> select * from test2;
ID
----------
1
2
3
SQL> insert into test2 values(4);
1 row created.
SQL> commit;
Commit complete.
mysql> select * from test2;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
+------+
4 rows in set (0.00 sec)
5.8.2 UPDATE
SQL> update test2 set id='5' where id='4';
1 row updated.
SQL> commit;
Commit complete.
mysql> select * from test2;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 5 |
+------+
4 rows in set (0.00 sec)
5.8.3 DELETE
SQL> delete from test2 where id<5;
3 rows deleted.
SQL> commit;
Commit complete.
mysql> select * from test2;
+------+
| id |
+------+
| 5 |
+------+
1 row in set (0.00 sec)
至此,DML操做測試完畢,注意,因爲以前配置過了初始化抽取,因此測試表test2的結構信息已經在以前的eini參數中經過指定oratmy.def傳遞到目標端,以後的eotomy和potomy參數中都不須要再添加defsfile ./dirdef/oratomy.def這句了
關於ORACLE->MYSQL的DDL同步說明:
根據官方文檔,因爲ogg不支持mysql 的 MyISAM 引擎,因此不能進行DDL的同步
注:goldengate對mysql只支持innodb引擎
create table mysql (name char(10)) engine=innodb;
6、同構和異構數據庫的雙路單向複製(ORACLE-ORACLE/ORACLE-MYSQL)
6.1 同構數據庫的單向複製(ORACLE-ORACLE)
內容與第四步一致,(略)…
6.2 異構數據庫的單向複製(ORACLE-MYSQL)
內容與第五步一致,(略)…
不一樣的只是在源端和目標端同時配置兩組複製鏈路,用於同構和異構數據之間的同步複製,能夠在目標端同時安裝2個OGG軟件,也能夠分別在1臺機器上裝OGG FOR ORACLE,另外一臺機器上裝OGG FOR MYSQL,源端配置好發往2個目標端的相關抽取組就能夠了
總結:在配置ORACLE->MYSQL初始化抽取這裏花了好多時間,也碰到了好多問題,由於是初次接觸MYSQL的緣故,不少東西都不懂,查了好多資料,不過最後都一一解決了,發現錯誤不可怕,經過本身的努力和堅持再解決之後,成就感油然而生,這是一次寶貴的學習經歷,把期間碰到的一些OGG方面的問題拿出來分享,但願對你們有所幫助!
-------------------------------------------------------------------------------------------------------
By aaron8219 Chinaunix Blog:http://blog.chinaunix.net/uid/24612962.html
原創內容,轉載請註明連接,謝謝!