docker单间mysql集群
docker pull mysql:5.6.43
docker run -itd --name mysql_master --restart=always \
-p 28002:3306 \
-e mysqld \
-e MYSQL_ROOT_PASSWORD=cloud \
-e MYSQL_USER=cloud \
-e MYSQL_PASSWORD=cloud \
-v /opt/mysql_master/data:/var/lib/mysql \
-d mysql:5.6.43
docker run -itd --name mysql_slave --restart=always \
-p 28003:3306 \
-e mysqld \
-e MYSQL_ROOT_PASSWORD=cloud \
-e MYSQL_USER=slave \
-e MYSQL_PASSWORD=slave \
-v /opt/mysql_slave/data:/var/lib/mysql \
-d mysql:5.6.43
docker exec -it mysql_master /bin/bash
cd etc/mysql/
apt-get update
apt-get install vim
vim my.cnf
[mysqld]
server_id=100
log-bin=mysql-bin
service mysql restart
docker restart mysql_master
docker exec -it mysql_master /bin/bash
mysql -u root -p
cloud
drop user 'slave'@'%';
flush privileges;
CREATE USER 'slave'@'%' IDENTIFIED BY 'slave';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
docker exec -it mysql_slave /bin/bash
cd etc/mysql/
apt-get update
apt-get install vim
vim my.cnf
[mysqld]
server-id=101
log-bin=mysql-slave-bin
relay_log=edu-mysql-relay-bin
service mysql restart
docker restart mysql_slave
docker exec -it mysql_slave /bin/bash
mysql -u root -p
cloud
show master status;
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/02152134c94b91b48ec95f4fee07f572.jpeg)
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql_master
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql_slave
change master to master_host='47.104.152.19', master_user='slave', master_password='slave', master_port=28002, master_log_file='mysql-bin.000002', master_log_pos= 512, master_connect_retry=30;
show slave status \G;
start slave;
reset slave;
root: slave
password: slave
root:root
password: cloud
使用start slave开启主从复制过程后,如果SlaveIORunning一直是Connecting,则说明主从复制一直处于连接状态,这种情况一般是下面几种原因造成的,我们可以根据 Last_IO_Error提示予以排除。
网络不通
检查ip,端口
密码不对
检查是否创建用于同步的用户和用户密码是否正确
pos不对
检查Master的 Position