Mysql Docker
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;
很久没有写博客了,感觉只要是不写博客,人就很变得很懒,学的知识点感觉还是记不住,渐渐地让我明白,看的越多,懂的越少(你这话不是有毛病吗?应该是看的越多,懂的越多才对),此话怎讲,当你在茫茫的前端知识库里面东看看,西看看的时候,很快就被海量的知识给淹没了,根本就不知道哪些是对的,哪些是错的,感觉好像这个也懂了,那个也懂了,但是真正写起来,脑子又一片空白,又好像什么都不懂,这种状态时有发生,这就叫不懂装懂,最根本的原因就是看的太多,写的太少,所以为了改掉这样毛病,把被动学习变成主动学习,接下来的日子,多写写,即使是写一些学习工作中遇到的坑也是好的,没事翻出来看看,还可以加深印象,好了,废话到处!