准备
配置环境变量:
添加一个MYSQL_HOME :G:\mysql(MYSQL的安装路径)
path中添加两个:G:\mysql\bin; G:\ogg;(ogg的解压路径)
Mysql配置(源端和目标端都要操作)
编辑G:\mysql\my.ini
- [client]
- port=3306
- [mysql]
- no-beep
- default-character-set=utf8
- [mysqld]
- port=3306
- datadir=D:/mysql/Data
- character-set-server=utf8
- default-storage-engine=INNODB
- sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
- log-output=FILE
- general-log=0
- general_log_file="LB.log"
- slow-query-log=1
- slow_query_log_file="LB-slow.log"
- long_query_time=10
- #log-bin = mysql-bin
- log-bin=D:/mysql/log/mysql-bin
- log_bin_index=D:/mysql/log/mysql-bin.index
- binlog_format=row
- binlog-ignore-db=oggddl
- log-error="LB.err"
- server-id=1
- secure-file-priv="C:/ProgramData/MySQL/MySQL Server 5.7/Uploads"
- max_connections=151
- table_open_cache=2000
- tmp_table_size=16M
- thread_cache_size=10
- myisam_max_sort_file_size=100G
- myisam_sort_buffer_size=8M
- key_buffer_size=8M
- read_buffer_size=0
- read_rnd_buffer_size=0
- innodb_flush_log_at_trx_commit=1
- innodb_log_buffer_size=1M
- innodb_buffer_pool_size=8M
- innodb_log_file_size=48M
- innodb_thread_concurrency=17
- innodb_autoextend_increment=64
- innodb_buffer_pool_instances=8
- innodb_concurrency_tickets=5000
- innodb_old_blocks_time=1000
- innodb_open_files=300
- innodb_stats_on_metadata=0
- innodb_file_per_table=1
- innodb_checksum_algorithm=0
- back_log=80
- flush_time=0
- join_buffer_size=256K
- max_allowed_packet=4M
- max_connect_errors=100
- open_files_limit=4161
- sort_buffer_size=256K
- table_definition_cache=1400
- binlog_row_event_max_size=8K
- sync_master_info=10000
- sync_relay_log=10000
- sync_relay_log_info=10000
- 注意:这里需要创建G:/mysql/log目录并且my.ini文件中的是/
DDL同步准备(源端和目标端都要操作)
- 注意:这里需要手工将ddl_install.cmd中的cp修改为copy
- ddl_install.cmd install root "root" 3306
- 这里的root 和 ‘’root’’是我mysql的用户名和密码
数据同步(源端和目标端)
在OGG的解压目录下执行ggsci
- GGSCI (DESKTOP-L2M11A2) > create subdirs
-
- G:\OGG\ogg123>install addservice
- Service 'GGSMGR' created.
- Install program terminated normally
注意:这里需要用管理员身份运行cmd去执行install addservice
MGR参数和进程(源和目标均需要配置)
G:\OGG\ogg123>ggsci
ggsci>edit param mgr --源端
- PORT 7809
- DYNAMICPORTLIST 7810-7910
- AUTORESTART EXTRACT *, RETRIES 5, WAITMINUTES 3, RESETMINUTES 60
- PURGEOLDEXTRACTS ./dirdat/*, usecheckpoints, minkeepdays 1
- LAGREPORTMINUTES 15
- LAGINFOMINUTES 30
- LAGCRITICALMINUTES 45
ggsci>edit param mgr --目标端
- PORT 7809
- DYNAMICPORTLIST 7810-7910
- AUTORESTART EXTRACT *, RETRIES 5, WAITMINUTES 3, RESETMINUTES 60
- PURGEOLDEXTRACTS ./dirdat/*, usecheckpoints, minkeepdays 1
- LAGREPORTMINUTES 15
- LAGINFOMINUTES 30
- LAGCRITICALMINUTES 45
配置完成后,源和目标均启动:
ggsci> start mgr
源端配置extract和pump进程(源端根据用户实际环境填写)
G:\OGG\ogg123>ggsci
ggsci>edit param eydcx
- EXTRACT EYDCX
- DBOPTIONS HOST 127.0.0.1, CONNECTIONPORT 3306
- SOURCEDB test, USERID root, PASSWORD root
- DISCARDFILE ./dirrpt/eydcx.dsc, APPEND, MEGABYTES 100
- REPORTCOUNT EVERY 1 MINUTES, RATE
- ddl include mapped
- EXTTRAIL ./dirdat/yd
- WILDCARDRESOLVE DYNAMIC
- dynamicresolution
- TRANLOGOPTIONS ALTLOGDEST G:\mysql\log\mysql-bin.index
- TABLE test.*;
注意:这里TRANLOGOPTIONS ALTLOGDEST参数的目录是\
ggsci>edit param dydcx
- EXTRACT dydcx
- PASSTHRU
- RMTHOST 10.65.28.122(目标服务器ip), MGRPORT 7809
- RMTTRAIL ./dirdat/yd
- DYNAMICRESOLUTION
- TABLE test.*;
增加ext和pump进程以及队列:
G:\OGG\ogg123>ggsci
ADD EXTRACT eydcx TRANLOG, BEGIN NOW
ADD EXTTRAIL ./dirdat/yd, EXTRACT eydcx, MEGABYTES 100
ADD EXTRACT dydcx, EXTTRAILSOURCE ./dirdat/yd
ADD RMTTRAIL ./dirdat/yd, EXTRACT dydcx, MEGABYTES 100
数据初始化
源端添加进程和队列
add extract exta, SourceisTable
源端配置进程
edit params exta
- extract exta
- DBOPTIONS HOST 127.0.0.1, CONNECTIONPORT 3306
- SOURCEDB test, USERID root, PASSWORD root
- rmthost 10.65.28.122, mgrport 7809
- rmtfile ./dirdat/ea, maxfiles 999999, megabytes 200, append
- reportcount every 60 seconds, rate
- table test.*;
源端启动进程
start exta
验证初始化数据捕获完毕
Info exta , 如果是stop就结束了
目标端添加进程和队列
add replicat repa, exttrail ./dirdat/ea , nodbcheckpoint
目标端配置进程
edit params repa
- replicat repa
- DBOPTIONS HOST 127.0.0.1, CONNECTIONPORT 3306
- TARGETDB test, USERID root, PASSWORD root
- REPERROR DEFAULT, DISCARD
- DISCARDFILE ./dirrpt/repa.dsc,APPEND,MEGABYTES 200
- reportcount every 60 seconds, rate
- Assumetargetdefs
- BATCHSQL
- GROUPTRANSOPS 2000
- MAP test.*, TARGET test.*;
目标端启动进程
start repa
验证初始化数据加载完毕
Info repa
如果是对应的文件号和位置值一致就结束了
删掉初始化进程及队列文件
源端: delete exta
目标端:stop repa
delete repa
删除dirdat下ea开头的文件
数据同步(目标端)
准备目标表的结构
dblogin SOURCEDB test, USERID root, PASSWORD root
目标端配置replicat参数(等待后续初始化完成再配置进程和队列,目标只配置replicat的参数文件,根据用户实际环境填写)
配置目标端投递进程
G:\OGG\ogg123>ggsci
ggsci>edit param rydcx
- REPLICAT rydcx
- DBOPTIONS HOST 127.0.0.1, CONNECTIONPORT 3306
- TARGETDB test, USERID root, PASSWORD root
- HANDLECOLLISIONS
- ASSUMETARGETDEFS
- DISCARDFILE ./dirrpt/RYDCX.DSC, PURGE
- ddl include mapped
- MAP test.*, TARGET test.*;
启动投递进程
ADD REPLICAT rydcx, EXTTRAIL ./dirdat/yd, nodbcheckpoint
START REPLICAT RYDCX
info all 查看进程状态
如果进程没有报错,表示配置成功,源端如果有数据插入,目标就会同步过来
如果哪个进程没有启动成功,查看日志命令view report 进程名字