mysql主从配置作业 一主一次
一、环境要求
主:192.168.211.138
从:192.168.221.139
二、配置主
1.添加
vim /etc/my.cnf
log-bin=mysql-bin
server-id=1
2.重启数据库生效
systemctl restart mysqld
3.建立同步账号
【1】创建用来传输数据的账号
create user 'repl'@'192.168.211.%' identified by 'repl123456';
【2】给这个账号赋予复制权限
grant replication slave on * . * to 'repl'@'192.168.211.%';
4.刷新授权
flush privileges;
5.查看权限情况
show grants for 'repl'@'192.168.211.%';
6.查看有哪些二进制日志文件
show binary logs;
7.查看当前正在使用的是哪一个二进制日志文件
show master status;
三、配置从
1.添加
vim /etc/my.cnf
log-bin=mysql-bin
server-id=2
2.重启生效
systemctl restart mysqld
9版本以后
change replication source to
source_host='192.168.211.138',
source_user='repl',
source_password='repl123456',
source_log_file='binlog.000003',
source_log_pos=1074,
source_port=3306;
9版本以前
change master to
master_host='192.168.211.138',
master_user='repl',
master_password='repl123456.',
master_log_file='binlog.000003',
master_log_pos=1074;
3.启动从库同步开关
9版本之前
start replica;
9版本前
start slave;
