master
# /etc/my.cnf
# server-id 节点ID 不能重复
server-id=1
log-bin=mysql-bin
# binlog-do-db=test 表示需要同步的数据库节点
# binlog-do-db=test
# binlog-ignore-db 表示不需要同步的数据库节点
# 每个数据库配置1条
# binlog-ignore-db=performance_schema
# binlog-ignore-db=mysql
# binlog-ignore-db=information_schema
slave
# slave server id
server-id=101
# 重启mysql
systemctl restart mysqld
# 查看master状态
show master status;
# 创建账号
CREATE USER 'repl'@'%' IDENTIFIED BY '123456';
# 分配权限
grant replication slave on *.* to 'repl'@'%' identified by '123456';
slave
# 在mysql控制台输入
语法: mysql> CHANGE MASTER TO MASTER_HOST = host, MASTER_PORT = port, MASTER_USER = user,
MASTER_PASSWORD = password;
CHANGE MASTER TO MASTER_HOST='192.168.5.212', MASTER_PORT=13306,MASTER_USER='repl', MASTER_PASSWORD='123456';
# 开启
start slave;
# 关闭
stop slave;
# 用于删除SLAVE数据库的relaylog日志文件 需要先stop
set slave;
show slave status \G;
# drop user 'repl'@'%';
flush privileges;