mysql在线建立半同步复制的从库
mysql在线建立半同步复制的从库
在主库和备库创建同步用的用户:
grant replication slave on *.* to repl@'%' identified by 'xxx';
(1)备份主库:
mysqldump -uroot -pxxx --routines --single_transaction --master-data=2 --databases testdb1 testdb2 > backup.sql
传输到从库:
scp backup.sql 192.168.2.22:/root/
(2)从库:
恢复备份:
mysql -uroot -pxxx < backup.sql
查看备份是的查看binlog和pos值
head -25 backup.sql
(3)设置同步点:
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)设置mysql半同步复制
主库:
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在重启时自动加载该功能,在/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