Giter Club home page Giter Club logo

mysql-replication's Introduction

MySQL Replication

A simple docker file to setup mysql databases with both master and slave ones.

Description

You can use this Docker file to setup a local development environment with master-slave MySQL databases architecture. Currently it supports only one master and one slave database in the wrapped start_servers.sh shell script, but it is possible to expand more slave through running command shown in that script.

Getting Started

  1. Ensure you have installed docker correctly, if not or do not know how to do this, you should read official installation documents;

Then, you have two different ways to run containers, one is to build the image by yourself, while the other one is to pull the image through docker hub directly.

Build The Image By Yourself

  1. Pull this repository to one of whatever directory whatever you like:
cd /any/directory/you/want/to/work/on
git clone [email protected]:Martin91/mysql-replication.git
  1. Build the image:
cd mysql-replication
docker build -t "any-docker-image-name-you-like" .
  1. After waiting a long time to finishing update apt and install mysql automatically, you can setup two containers now:
chmod +x start_servers.sh
./start_servers.sh

Pull From Docker Hub

docker pull martin91/mysql_server
docker run --name=mysql_master -p 3306 -e master_role=true -d martin91/mysql_server
# Wait about 5 seconds before run the below command
docker run --name=mysql_slave --link=mysql_master -p 3306 -e slave_role=true -d martin91/mysql_server

Connect Servers Locally

docker-machine ip  # record your vm's ip address here
docker ps          # record ports of containers related to mysql
mysql -uroot -h{vm's ip address} -P{containers binded port on the vm}

ATTENTIONS!

It is strongly recommended to setup these containers ONLY under development, test or staging evironments. Use it for production environment is VERY DANGEROUS. Instead, if you are looking for a safe and reliable image, you should checkout to MySQL official image: official: mysql.

TODO

More flexible commands based on environment variables, includes:

  • mount file dir as persisted data dir
  • multiple master
  • slave servers count
  • explicitly specify ports binding
  • database users and passwords
  • refactor based on docker-compose
  • etc...

mysql-replication's People

Contributors

martin91 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.