mysql 5.7 主从配置(一主一从)

首先在两台机器上分别安装mysql5.7,然后开始下面的配置

1.主库开启bin-log

server-id=1 #服务器id (主从必须不一样)

log-bin=mysql-bin #打开日志(主机需要打开),这个mysql-bin也可以自定义,这里也可以加上路径

#作为主机的配置

binlog-do-db=employees #要给从机同步的库

log-bin-index=master-bin.index

#binlog-do-db=

binlog-ignore-db=mysql #不给从机同步的库(多个写多行)

binlog-ignore-db=information_schema

binlog-ignore-db=performance_schema

binlog-ignore-db=sys

expire_logs_days=7 #自动清理 7 天前的log文件,可根据需要修改

 

 

2.登录主库 创建同步用户 slaver

CREATE USER 'slaver'@'%' IDENTIFIED BY 'root123456';

授权

 grant replication slave on *.* to 'slaver'@'%' identified by 'root123456';

 

3.从库配置

 

[mysqld]

basedir=/usr/local/mysql #mysql路径

datadir=/data/mysqldata #mysql数据目录

socket=/tmp/mysql.sock

server_id=2 #MySQLid 后面2个从服务器需设置不同

port=3306

 #加上以下参数可以避免更新不及时,SLAVE 重启后导致的主从复制出错。

read_only = 1

master_info_repository=TABLE

relay_log_info_repository=TABLE

#relay_log_recovery=1 #从机禁止写

#super_read_only=1 #从机禁止写

relay-log-index=slave-relay-bin.index

relay-log=slave-relay-bin

 

4.登录从库 设置如下

mysql -uroot -p123456

mysql> stop slave;

mysql> change master to

-> master_host='139.198.13.18', #master的ip

-> master_user='slaver', #备份用户名

-> master_password='root123456', #密码

-> master_log_file='mysql-bin.000001', #要与master的参数一致 登录主库 show marster status查看

-> master_log_pos=154; #且要与master的参数一致 登录主库 show marster status 查看

mysql> start slave;

 

change master to master_host='139.198.13.18', master_user='slaver',  master_password='root123456',master_log_file='mysql-bin.000001',master_log_pos=154;

 

你可能感兴趣的:(linux)