Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

MySQL Master Slave Using Docker

How to Run?

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-slave

Create new environment file.

cp .env.example .env

Change the values as you want. Example:

MYSQL_DATABASE=docker_db
MYSQL_USER=docker_user
MYSQL_PASSWORD=docker_pass
MYSQL_ALLOW_EMPTY_PASSWORD=1

Run the .sh file.

bash run.sh

or

./run.sh

Make sure the containers is up. Then accessing the master and slave.

docker exec -it mysql_master mysql -u docker_user -pdocker_pass
docker exec -it mysql_slave mysql -u docker_user -pdocker_pass

Test Replication

Try 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;"

Test replication

Tear Down

To stop and remove everything cleanly:

docker compose down -v
rm -rf master/data/* slave/data/*

Demo

Demo