Skip to content

A bash script to download and run a replicating mysql cluster running in docker containers

Notifications You must be signed in to change notification settings

dougjohnson/mysql_replication_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Replicating MySQL Cluster Demo

This demo is a lightweight bash script to bring together two Docker Containers to create a replicating MySQL cluster for testing / development purposes.

It is as simple as running ./start_cluster, passing in the number of slaves you want in your cluster like so:

./start_cluster -n 2

The script will pull a master image and a slave image from the docker hub and will start one master and as many slaves as you specify, with replication set up and working out of the box.

Ideal for testing read-write splitting in your web application.

Starting master / slave manually

Starting the master:

docker run --name my-master -d doug/mysql-master

The slaves will need to --link to whatever the master’s --name is set to

The privileged user / password is by default root / root
Override this by setting the env variables, $USERNAME and $PASSWORD:

docker run --name my-master -e "USERNAME=fuji" -e "PASSWORD=yama" -d doug/mysql-master

Starting the slaves:

docker run --name my-slave1 --link my-master:my-master -e "MYSQL_MASTER_HOST=my-master" -e "SERVER_ID=1" -d doug/mysql-slave

As well as using --link to link to the master, the MYSQL_MASTER_HOST env variable needs to be set

Each slave needs to be given a unique SERVER_ID

No need to snapshot a slave – masters can be snapshotted and new slaves will always catch up

root / root can be overridden in the same way as for a master

Slaves have a default readonly user set who only has select privileges: readonly / readonly
This username / password can be overridden by passing in the READONLY_USERNAME and READONLY_PASSWORD environment variables

Requirements

  • Docker
  • Internet

License

MIT License

About

A bash script to download and run a replicating mysql cluster running in docker containers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages