参考 https://dev.mysql.com/doc/refman/8.0/en/replication-howto.html
1,关闭防火墙
对主服务器master关闭 192.168.245.132slave从服务器也关闭192.168.245.133/etc/init.d/iptables stop# 永久关闭chkconfig iptables off
2,配置主服务器132
vi /usr/local/mysql/my.cnf在[mysqld]节点下配置log_bin=mysql-binserver-id=132 (为ip地址的最后一段)
3,启动mysql服务,并连接
service mysql start
4,授权slave服务器 此处的IP为slave服务器
mysql>GRANT REPLICATION SLAVE ON *.* to 'root'@'192.168.245.133' identified by 'root';####Mysql8下执行:mysql>GRANT REPLICATION SLAVE ON *.* to 'root'@'%';
5, 查看master服务器的状态
show master status;
6,配置从服务器
vi /usr/local/mysql/my.cnf在[mysqld]节点下配置log_bin=mysql-binserver-id=133 (为ip地址的最后一段)
7,启动mysql服务并连接
8,在从服务器中执行同步语句
change master tomaster_host='192.168.245.132',master_user='root',master_password='root',master_log_file='第五步结果中的file字段值',master_log_pos='第五步结果中的Position'字段值;
9,启动slave
start slave;
10 查看slave状态
show slave status\G
