mysql在線建立半同步復(fù)制的從庫
mysql在線建立半同步復(fù)制的從庫
在主庫和備庫創(chuàng)建同步用的用戶:
grant replication slave on *.* to repl@'%' identified by 'xxx';
(1)備份主庫:
mysqldump -uroot -pxxx --routines --single_transaction --master-data=2 --databases testdb1 testdb2 > backup.sql
傳輸?shù)綇膸欤?br />
scp backup.sql 192.168.2.22:/root/
(2)從庫:
恢復(fù)備份:
mysql -uroot -pxxx < backup.sql
查看備份是的查看binlog和pos值
head -25 backup.sql
(3)設(shè)置同步點(diǎn):
change master to master_host="host1",master_user="repl",master_password="xxx",master_log_file="mysql-bin.000012",master_log_pos=97896903;
start slave;
(4)設(shè)置mysql半同步復(fù)制
主庫:
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
mysql> set global rpl_semi_sync_master_enabled=1;
mysql> set global rpl_semi_sync_master_timeout=1000;
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
mysql> set global rpl_semi_sync_slave_enabled=1;
mysql> show global status like 'rpl%';
為了讓mysql在重啟時(shí)自動(dòng)加載該功能,在/etc/my.cnf 加入:
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000
rpl_semi_sync_slave_enabled=1
備庫:
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
mysql> set global rpl_semi_sync_master_enabled=1;
mysql> set global rpl_semi_sync_master_timeout=1000;
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
mysql> set global rpl_semi_sync_slave_enabled=1;
在/etc/my.cnf中加入:
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000
rpl_semi_sync_slave_enabled=1