Mysql主从复制

master服务器设置

1.安装mysql并启动

yum -y install mysql-server mysql

2.启动mysql服务

systemctl enable mysqld;systemctl start mysqld

3.修改root密码

alter user 'root'@'localhost' identified by '989891';

4.关闭防火墙

# systemctl disable firewalld
# sed -i -r '/SELINUX=/c\SELINUX=disabled' /etc/selinux/config

5.修改配置文件

echo "server-id=1"  >> /etc/my.cnf.d/mysql-server.cnf 

6.创建slave连接master的账号

mysql> create user slave identified by "98989";

mysql> grant replication slave on *.* to slave;
mysql> flush privileges;

slave服务器设置

1~4同master配置

5.修改配置文件

echo "server-id=2"  >> /etc/my.cnf.d/mysql-server.cnf 

6.设置slave同步

mysql> stop slave;
mysql> change master to master_host='192.168.98.201',master_user='slave',master_password='98989',master_log_file='binlog.000002';
mysql> start slave;

7.验证是否通讯

 show slave status \G;

发表评论