1
|
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql.sock |
1 2 3 |
create user 'replicate'@'%' identified by '123456'; grant replication slave on *.* to 'replicate'@'%'; flush privileges; |
或者
1 2 3 |
create user 'replicate'@'192.168.220.58' identified by '123456'; grant replication slave on *.* to 'replicate'@'192.168.220.58'; flush privileges; |
1
|
select user,host from mysql.user; |
1
|
exit
|
1
|
/usr/local/mysql/bin/mysql -h192.168.222.120 -P3306 -ureplicate -p123456 -S /data/mysql/run/mysql.sock |
1
|
vim /etc/my.cnf
|
[mysqld] server-id=1 log-bin=/data/mysql/data/mysql-bin relay_log=/data/mysql/relaylog/relay-bin
1
|
service mysql restart |
或者
1 2 |
/usr/local/mysql/bin/mysqladmin -uroot -p123456 shutdown -S /data/mysql/run/mysql.sock /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf & |
1 2 |
ps -ef | grep mysql netstat -anpt | grep mysql |
1
|
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql.sock |
1
|
install plugin rpl_semi_sync_master soname 'semisync_master.so'; |
查看插件rpl。
1
|
show plugins; |
1
|
set global rpl_semi_sync_master_enabled=1; |
1
|
show variables like '%rpl_semi_sync_master_enabled%'; |
值为ON说明启动成功。
1
|
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql.sock |
同步方式有2种方式:传统方式和GTID方式。MySQL版本在5.7及以上时推荐使用GTID方式。
1 2 3 4 5 |
set global enforce_gtid_consistency='off'; set global gtid_mode='on_permissive'; set global gtid_mode='off_permissive'; set global gtid_mode='off'; show variables like '%gtid_mode%'; |
1 2 3 4 5 |
set global enforce_gtid_consistency='on'; set global gtid_mode='off_permissive'; set global gtid_mode='on_permissive'; set global gtid_mode='on'; show variables like '%gtid_mode%'; |
gtid_mode设置顺序:
gtid_mode的值只能相邻状态相互修改。例如:从OFF到ON,只能从OFF修改为OFF_PERMISSIVE,然后从OFF_PERMISSIVE修改为ON_PERMISSIVE,再从ON_PERMISSIVE修改为ON;反之亦然,即OFF <->OFF_PERMISSIVE <-> ON_PERMISSIVE <-> ON。
1
|
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql.sock |
1
|
show master status; |
File列和Position列都有值则说明正常。记录File参数值(binlog日志文件)和Position参数值(binlog中最新操作的位置),后面配置从库6时会用到这2个参数值。
1
|
exit
|