1:创建用户给slave使用slave将会通过这个账号同步数据
修改用户密码等级:
set global validate_password_length=1;
set global validate_password_policy=0;
创建用户:
create user repl identified by 'repl';
2:给账号权限
grant replication slave on *.* to 'repl'@'%' identified by 'repl';
3:使用命令vi /etc/my.cnf打开mysql配置文件并添加:
log-bin=mysql-bin
server-id=217
4:重启mysql:
systemctl start mysqld
登陆mysql使用命令show master status查询对应日志文件和起始读取
5:使用命令vi /etc/my.cnf打开mysql配置文件在slave上配置文件里面加如下配置
server-id=217
relay-log=slave-relay-bin
relay-log-index=slave-relay-bin.index
read_only=1
6:登陆mysql
7:运行命令:
change master to master_host='master的ip',master_port=端口号,master_user='先前创建的账号',master_password='对应密码',master_log_file='日志文件名称',master_log_pos=读取起始位;
change master to master_host='192.168.31.217',master_port=3306,master_user='repl',master_password='repl',master_log_file='mysql-bin.000001',master_log_pos=154;
8:在mysql里面运行命令启动服务:
start slave;
9:show slave status\G;查看连接状态
都为yes,表示成功了