代码编织梦想

两台机器做(主:master,从:slave,版本:5.7)

1.域名解析

vim /etc/hosts

格式如下图: 

 2.关闭防火墙和selinux:

systemctl stop firewalld

systemctl disable firewalld

setenfore 0

vi /etc/selinux/config

把 SELINUX  修改为 disable

 3.配置master:

# vi /etc/my.cnf    
	validate_password=off //修改为弱密码登录
	log-bin
	server-id=1
	gtid_mode=ON
	enforce_gtid_consistency=1
mysql> grant replication slave,super,reload on *.* to slave@'%' identified by '数据库密码';  //授权远程账户登录
mysql> flush privileges; //刷新权限

4.slave配置:

vim /etc/my.cnf
	validate_password=off //弱密码
	log-bin	
	server-id=2
	gtid_mode=ON
	enforce_gtid_consistency=1

5.重启mysql

master:

systemctl restart mysqld

slave:

systemctl restart mysqld

6.再次配置slave:

mysql > change master to 
			master_host='master',
			master_user='slave',
			master_password='123',
			master_auto_position=1;
mysql > start slave;   //启动slave
mysql > show slave status\G  //查看状态

注意:IO和SQL状态必须都为yes,否则不生效。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_62879993/article/details/129674566