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主从复制的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-23BinLog入门:新手必读的MySQL二进制日志指南
- 2024-10-23Binlog入门:MySQL数据库的日志管理指南
- 2024-10-22MySQL数据库入门教程:从安装到基本操作
- 2024-10-22MySQL读写分离入门教程:轻松实现数据库性能提升
- 2024-10-22MySQL分库分表入门教程
- 2024-10-22MySQL慢查询的诊断与优化指南
- 2024-10-22MySQL索引入门教程:快速理解与应用指南
- 2024-10-22MySQL基础入门教程:从安装到基本操作
- 2024-10-22MySQL数据库中的Binlog详解与操作教程
- 2024-10-12部署MySQL集群项目实战:新手入门教程