Skip to content

Latest commit

 

History

History
88 lines (63 loc) · 1.76 KB

README_en.md

File metadata and controls

88 lines (63 loc) · 1.76 KB

Docker MySQL master-slave replication

docker-compose构建 mysql 主从复制(读写分离)集群
MySQL master-slave replication with using Docker.

Run

To run this examples you will need to start containers with "docker-compose" and after starting setup replication. See commands inside ./build.sh.

Create 3 MySQL containers with master-slaves row-based replication

./build.sh

Make changes to master

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)'"

Read changes from slaves

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

Troubleshooting

Check Logs

docker-compose logs

Start containers in "normal" mode

Go through "build.sh" and run command step-by-step.

Check running containers

docker-compose ps

Clean data dir

rm -rf ./master/data/*
rm -rf ./slave/data/*
rm -rf ./slave2/data/*

Run command inside "mysql_master"

docker exec mysql_master sh -c 'mysql -u root -p111 -e "SHOW MASTER STATUS \G"'

Run command inside "mysql_slaves"

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"'

Enter into "mysql_master"

docker exec -it mysql_master bash

Enter into "mysql_slaves"

docker exec -it mysql_slave bash
docker exec -it mysql_slave2 bash