To run this project just make sure you're in container-stuffs directory, then navigate to single-node/mysql-master-slave.
cd single-node/mysql-master-slaveCreate new environment file.
cp .env.example .envChange the values as you want. Example:
MYSQL_DATABASE=docker_db
MYSQL_USER=docker_user
MYSQL_PASSWORD=docker_pass
MYSQL_ALLOW_EMPTY_PASSWORD=1Run the .sh file.
bash run.shor
./run.shMake sure the containers is up. Then accessing the master and slave.
docker exec -it mysql_master mysql -u docker_user -pdocker_passdocker exec -it mysql_slave mysql -u docker_user -pdocker_passTry to create new table, create new database or others modification to make sure the replication is running.
docker exec -it mysql_master mysql -u root -e "CREATE DATABASE IF NOT EXISTS demo; USE demo; CREATE TABLE test (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50)); INSERT INTO test (name) VALUES ('Hello from master');"Then check the slave:
docker exec -it mysql_slave mysql -u root -e "SELECT * FROM demo.test;"To stop and remove everything cleanly:
docker compose down -v
rm -rf master/data/* slave/data/*
