Giter VIP home page Giter VIP logo

mysql-cluster's Introduction

docker-compose构建mysql主从复制集群

默认用户名 root 密码 111 docker-compose构建 mysql 主从复制(读写分离)集群
MySQL master-slave replication with using Docker.

运行

git clone https://github.com/docker-box/mysql-cluster.git
cd mysql-cluster
./build.sh

可以在build.sh内自定义对应参数

提示: 运行前需要确保安装了docker和docker-compose,具体安装方法请参考官网

如果想手动安装, 则可以按照build.sh内的命令来手动执行即可

测试看看效果

  1. 给主库创建一个表, 并添加两条数据
docker exec mysql_master sh -c "export MYSQL_PWD=111; mysql -u root mydb -e 'create table code(code int); insert into code values (100), (200)'"
  1. 查看两个从库是否同步了该表以及数据
docker exec mysql_slave sh -c "export MYSQL_PWD=111; mysql -u root mydb -e 'select * from code \G'"
docker exec mysql_slave2 sh -c "export MYSQL_PWD=111; mysql -u root mydb -e 'select * from code \G'"

如果前边的安装正确的话, 就可以看到第一步插入的两条数据了

相关命令

查看docker-compose运行日志

docker-compose logs

查看运行的docker容器

docker-compose ps

查看主库运行状态

docker exec mysql_master sh -c 'mysql -u root -p111 -e "SHOW MASTER STATUS \G"'

查看从库运行状态

docker exec mysql_slave sh -c 'mysql -u root -p111 -e "SHOW SLAVE STATUS \G"'
docker exec mysql_slave2 sh -c 'mysql -u root -p111 -e "SHOW SLAVE STATUS \G"'

进入主库

docker exec -it mysql_master bash

进入从库

docker exec -it mysql_slave bash
docker exec -it mysql_slave2 bash

mysql-cluster's People

Contributors

fizzday avatar zhangdachen avatar

Forkers

xiaozhu0232

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.