docker-compose构建 mysql 主从复制(读写分离)集群
MySQL master-slave replication with using Docker.
To run this examples you will need to start containers with "docker-compose" and after starting setup replication. See commands inside ./build.sh.
./build.sh
docker exec mysql_master sh -c "export MYSQL_PWD=111; mysql -u root mydb -e 'create table code(code int); insert into code values (100), (200)'"
docker exec mysql_slave sh -c "export MYSQL_PWD=111; mysql -u root mydb -e 'select * from code \G'"
docker exec mysql_slave2 sh -c "export MYSQL_PWD=111; mysql -u root mydb -e 'select * from code \G'"
if work normal, you will get the save rows as you have inserted into master before
docker-compose logs
Go through "build.sh" and run command step-by-step.
docker-compose ps
rm -rf ./master/data/*
rm -rf ./slave/data/*
rm -rf ./slave2/data/*
docker exec mysql_master sh -c 'mysql -u root -p111 -e "SHOW MASTER STATUS \G"'
docker exec mysql_slave sh -c 'mysql -u root -p111 -e "SHOW SLAVE STATUS \G"'
docker exec mysql_slave2 sh -c 'mysql -u root -p111 -e "SHOW SLAVE STATUS \G"'
docker exec -it mysql_master bash
docker exec -it mysql_slave bash
docker exec -it mysql_slave2 bash