1、安装docker,查看https://www.cnblogs.com/winstonsias/p/11179361.html
2、拉取mysql镜像,我用的mysql5.6
3、启动master和slave1容器
3/1、创建宿主文件夹:
/www/mysql_master/conf
/www/mysql_master/data
/www/mysql_master/logs
/www/mysql_slave1/logs
/www/mysql_slave1/data
/www/mysql_slave1/logs
3/2、运行容器:
docker run -p 3306:3306 --name mysql_master -v /www/mysql_master/conf:/etc/mysql/conf.d -v /www/mysql_master/logs:/logs -v /www/mysql_master/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
docker run -p 3307:3306 --name mysql_slave1 -v /www/mysql_slave1/conf:/etc/mysql/conf.d -v /www/mysql_slave1/logs:/logs -v /www/mysql_slave1/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
具体的参数自行查找
4、查看是否运行
docker ps
5、进入master
docker exec -it mysql_master bash
>>mysql -uroot -p123465
>>grant all privileges on *.* to master_slave@'%' identified by '123456';
>>flush privileges;
>>show master statusG;
6、进入slave1
docker exec -it mysql_slave1 bash
>>mysql -uroot -p123465
CHANGE MASTER TO MASTER_HOST='172.17.0.3',MASTER_PORT=3306,MASTER_USER='master_slave',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000005',MASTER_LOG_POS=上一步骤查到的position;
注意:host是master容器的ip 具体查看方式,可以进入master容器 cat /etc/hosts, MASTER_LOG_FILE、MASTER_LOG_POS为 show master status里面的内容
OK,大功告成