Docker部署Mysql主从复制
在docker内部,mysql5.7 与mysql8.0 目录存放位置是不一样的
echo net.ipv4.ip_forward=1>>/etc/sysctl.conf
sysctl -p
service network restart
systemctl restart docker
mkdir mysql
mkdir mysql/master
mkdir mysql/slave1
mkdir mysql/slave2
vi mysql/master.cnf
[mysqld]
server-id = 1
log-bin=mysql-bin
binlog-ignore-db=mysql
vi mysql/slave1.cnf
[mysqld]
server-id = 2
log-bin=mysql-slave-bin
relay_log=edu-mysql-relay-bin
binlog-ignore-db=mysql
log_bin_trust_function_creators=true
slave_skip_errors=1062
cp mysql/slave1.cnf mysql/slave2.cnf
docker network create mysql_list
docker run --name master --net mysql_list -e MYSQL_ROOT_PASSWORD=000000 -p 3306:3306 \
-v /root/mysql/master:/var/lib/mysql \
-v /root/mysql/master.cnf:/etc/my.cnf \
-d mysql:5.7
docker run --name slave1 --net mysql_list -e MYSQL_ROOT_PASSWORD=000000 -p 3307:3306 \
-v /root/mysql/slave1:/var/lib/mysql \
-v /root/mysql/slave1.cnf:/etc/my.cnf \
-d mysql:5.7
docker run --name slave2 --net mysql_list -e MYSQL_ROOT_PASSWORD=000000 -p 3308:3306 \
-v /root/mysql/slave2:/var/lib/mysql \
-v /root/mysql/slave2.cnf:/etc/my.cnf \
-d mysql:5.7
docker exec -it master /bin/bash
mysql -uroot -p000000
grant replication slave on *.* to 'root'@'%' identified by '000000';
flush privileges;
show master status;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '000000';
FLUSH PRIVILEGES;
docker exec -it slave1 /bin/bash
docker exec -it slave2 /bin/bash
mysql -uroot -p000000
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '000000';
FLUSH PRIVILEGES;
#"master_log_file"和"master_log_pos" 在master机上"show master status;"
change master to master_host='172.18.0.2',master_user='root',master_password='000000',master_port=3306,master_log_file='mysql-bin.000001',master_log_pos=154;
## 启动主从复制
start slave;
## 再查看主从同步状态
show slave status\G;
## 停止复制
stop slave;
标签:bin,Mysql,cnf,master,mysql,Docker,root,docker
From: https://www.cnblogs.com/createhm/p/16699865.html