Set-up simple mysql master slave replication: master and 2 slaves
./build.sh- Check that there are not tables in slaves
docker exec mysql_slave_1 sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; SHOW TABLES \G'"docker exec mysql_slave_2 sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; SHOW TABLES \G'"- Create a table in master
docker exec mysql_master sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; CREATE TABLE IF NOT EXISTS data(task_id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL)'"- Check again that there are the table
datain slaves
docker exec mysql_slave_1 sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; SHOW TABLES \G'"
*************************** 1. row ***************************
Tables_in_mydb: data docker exec mysql_slave_2 sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; SHOW TABLES \G'"
*************************** 1. row ***************************
Tables_in_mydb: data- Insert some rows into
datatable in master
docker exec mysql_master sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; INSERT INTO data (title) VALUES (\"Example_1\"), (\"Example_2\")'"- Check
datatable in slaves
docker exec mysql_slave_1 sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; SELECT * FROM data'"
task_id title
1 Example_1
2 Example_2docker exec mysql_slave_2 sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; SELECT * FROM data'"
task_id title
1 Example_1
2 Example_2docker-compose stop mysql_slave_1Insert more data to master
docker exec mysql_master sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; INSERT INTO data (title) VALUES (\"Example_3\"), (\"Example_4\")'"Turn on slave
docker-compose up -d mysql_slave_1Check that data was replicate from the lost period of time
docker exec mysql_slave_1 sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; SELECT * FROM data'"
task_id title
1 Example_1
2 Example_2
3 Example_3
4 Example_4Delete column title from the first slave
docker exec mysql_slave_1 sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; ALTER TABLE data DROP COLUMN title'"
docker exec mysql_slave_1 sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; SELECT * FROM data'"
task_id
1
2
3
4Insert more data to master and check slave. New data replicated to the remaining column
docker exec mysql_master sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; INSERT INTO data (title) VALUES (\"Example_5\")'"
docker exec mysql_slave_1 sh -c "export MYSQL_PWD=111; mysql -u root -e 'USE mydb; SELECT * FROM data'"
task_id
1
2
3
4
5