MySql5.7主从配置

记录

环境:ubuntu16.04,mysql5.7

主机:192.168.1.240,192.168.1.241;241为Salve

1.安装mysql

sudo apt-get install mysql-server

2.为master增加slave用户

进入mysql

grant replication slave on *.* to 'slave'@'192.168.1.241' identified by 'password';

3.编辑配置文件

master:

vim /etc/mysql/mysql.conf.d/mysqld.cnf

bind-address = 192.168.1.240 #这个一定要配,否则Slave连不上
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
relay-log=mysql-relay-bin
log_slave_updates=on
auto_increment_increment=2
auto_increment_offset=1

slave:

server-id = 2
auto_increment_increment=2
auto_increment_offset=2

4.在Master和Slave上创建相同的库与表

5.开启Slave

(1)240查询Master日志Position

show master status;

(2)在241设置Slave并启动

change master to master_host='192.168.1.240',master_user='slave',master_password='password',master_port=3306,MASTER_LOG_FILE='mysql-bin.000007', MASTER_LOG_POS=1068;

start slave;

查询slave状态

show slave status\G;

进行数据验证

上一篇:mysql5.6主从配置


下一篇:关于opacity透明度子元素继承现象的若干研究以及hack方法