数据库
首页 > 数据库> > docker mysql主从复制

docker mysql主从复制

作者:互联网

docker network create --subnet=172.10.0.0/24 docker-network

mkdir -p /data/docker/mysql/master/cnf & mkdir -p /data/docker/mysql/master/data & vim /data/docker/mysql/master/cnf/mysql.cnf

[mysqld]
server-id=1
log-bin=master-bin
binlog_cache_size=1M
binlog_format=mixed

docker run -d --name mysql-master \
-p 3407:3306 \
--net docker-network --ip 172.10.0.13 \
-v /data/docker/mysql/master/data:/var/lib/mysql \
-v /data/docker/mysql/master/cnf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=password \
-d mysql:5.7

docker exec -it mysql-master /bin/bash

mysql -uroot -ppassword

GRANT REPLICATION SLAVE ON *.* to 'reader'@'%' identified by 'reader###123';

show slave status \G

从1
mkdir /data/docker/mysql/slave1/cnf -p & mkdir /data/docker/mysql/slave1/data -p & vim /data/docker/mysql/slave1/cnf/mysql.cnf

[mysqld]
server-id=2
log-bin=mysql-slave-bin
relay_log=edu-mysql-relay-bin
log_bin_trust_function_creators=true
binlog_cache_size=1M
binlog_format=mixed
slave_skip_errors=1062

docker run -d --name mysql-slave1 \
-p 3408:3306 \
--net docker-network --ip 172.10.0.11 \
-v /data/docker/mysql/slave1/data:/var/lib/mysql \
-v /data/docker/mysql/slave1/cnf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=password \
-d mysql:5.7

docker exec -it mysql-slave1 /bin/bash

mysql -uroot -ppassword

change master to master_host='172.10.0.13',master_user='reader',master_password='reader###123',master_log_file='master-bin.000003',master_log_pos=439;
start slave;
show slave status \G

从2
mkdir /data/docker/mysql/slave2/cnf -p & mkdir /data/docker/mysql/slave2/data -p & vim /data/docker/mysql/slave2/cnf/mysql.cnf

[mysqld]
server-id=3
log-bin=mysql-slave-bin
relay_log=edu-mysql-relay-bin
log_bin_trust_function_creators=true
binlog_cache_size=1M
binlog_format=mixed
slave_skip_errors=1062

docker run -d --name mysql-slave2 \
-p 3409:3306 \
--net docker-network --ip 172.10.0.12 \
-v /data/docker/mysql/slave2/data:/var/lib/mysql \
-v /data/docker/mysql/slave2/cnf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=password \
-d mysql:5.7

docker exec -it mysql-slave2 /bin/bash

mysql -uroot -ppassword

change master to master_host='172.10.0.13',master_user='reader',master_password='reader###123',master_log_file='master-bin.000003',master_log_pos=439;
start slave;
show slave status \G

标签:主从复制,--,cnf,master,mysql,docker,data
来源: https://www.cnblogs.com/yz-w/p/16333525.html