docker mysql主从复制

2022/6/2 2:21:16

本文主要是介绍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



这篇关于docker mysql主从复制的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程