前提条件:服务器搭建MySQL并且可成功运行

 

No1:编辑主库、从库的配置文件  /etc/my.cnf

 

主库[ mysqld ]下编辑

server-id = 1

log-bin= mysql-bin

binlog_format=mixed

linux下 MYSQL主从搭建

 

从库[ mysqld ]下配置

# 从库配置
server-id=2
log-bin= binlog
binlog_format=mixed
replicate_wild_do_table=oldboy.%
replicate_wild_ignore_table=mysql.%

linux下 MYSQL主从搭建

No2:重启主库、从库mysql服务使配置生效

systemctl restart mysqld

linux下 MYSQL主从搭建

 

NO3:在主库上创建slave用户,并指定该用户只能在主机132.232.104.234上登录

mysql>grant replication slave on *.* to 'qtcheng'@'132.232.104.234' identified by 'qtcheng';

linux下 MYSQL主从搭建

 

No4 : 在从库132.232.100.177上登录到主库132.232.104.234

mysql -u admin -h 132.232.104.234 -p

linux下 MYSQL主从搭建

 

No5: 在主库上查询

select user,host from mysql.user;

linux下 MYSQL主从搭建

 

No6:锁主库的表并查询master的状态值,供步骤14使用

flush tables with read lock;

show master status;

linux下 MYSQL主从搭建

 

No7 :准备备份的库

linux下 MYSQL主从搭建

 

No8:解锁主库表unlock tables;

linux下 MYSQL主从搭建

No9:在从库上执行

stop slave;

change master to master_host='132.232.104.234',master_user='qtcheng',master_password='******',master_log_file='mysql-bin.000029',master_log_pos=1110;

start salve;

linux下 MYSQL主从搭建

 

No10:从库查看slave status 的状态

show slave status\G;

linux下 MYSQL主从搭建

 

主库insert ,从库select  ,恭喜你 搭建成功啦

 

文章原链接:https://blog.csdn.net/dutiantian_csdn/article/details/81980718

相关文章: