1.master配置
1.1输入vim /etc/my.cnf,编辑配置文件
添加以下内容
#主服务器唯一id
server_id=1
#启用二进制日志
log_bin=master_log
#设置不要复制的数据库
binlog_ignore_db=mysql
binlog_ignore_db=information_schema
binlog_ignore_db=performance_schema
binlog_ignore_db=sys
#设置需要复制的数据库
binlog_do_db=test
#设置logbin格式,默认STATEMENT,建议使用MIXED
binlog_format=MIXED
1.2重启mysql输入systemctl restart mysqld,查看mysql状态systemctl status mysqld
1.3创建slave用户并修改密码(以便客户端工具操作)
create user 'slave'@'%' identified by 'slave';
ALTER USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY 'slave';
1.4授权
grant replication slave on *.* to 'slave'@'%';
1.5刷新权限flush privileges;
1.6查看master状态show master status;记住日志文件名和偏移量
2.slave配置
2.1输入vim /etc/my.cnf,编辑配置文件
添加以下内容
从服务器唯一id
server_id=2
#启用中继日志
relay_log=relay_log
2.2重启mysql输入systemctl restart mysqld
2.3停止slave,输入stop slave;
2.4配置主库信息
change master to master_host='192.168.0.105',master_user='slave',master_password='slave',master_log_file='master_log.000007',master_log_pos=2467;
2.5开启slave,输入start slave;
2.6查看slave状态show slave status \G;没有error并且以下两项位yes,就成功了
2.7如果start slave报错Slave failed to initialize relay log info structure from the repository,先执行reset slave;在重新进行2.4,2.5步骤