https://github.com/omgzui/mysql_m_s
mysql主从
https://github.com/omgzui/mysql_m_s
docker docker-compose master-slave mysql
Last synced: about 2 months ago
JSON representation
mysql主从
- Host: GitHub
- URL: https://github.com/omgzui/mysql_m_s
- Owner: OMGZui
- License: mit
- Created: 2019-01-31T08:12:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-31T08:16:16.000Z (over 7 years ago)
- Last Synced: 2025-12-27T02:52:56.953Z (6 months ago)
- Topics: docker, docker-compose, master-slave, mysql
- Language: Dockerfile
- Size: 2.93 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mysql主从
```bash
# 准备容器
docker pull mysql:5.5
# 目录
├── LICENSE
├── README.md
├── docker-compose.yml
├── master
│ ├── Dockerfile
│ ├── docker-entrypoint-initdb.d
│ │ └── init.sql
│ └── my.cnf
├── slave1
│ ├── Dockerfile
│ ├── docker-entrypoint-initdb.d
│ │ └── init.sql
│ └── my.cnf
└── slave2
├── Dockerfile
├── docker-entrypoint-initdb.d
│ └── init.sql
└── my.cnf
# 启动
docker-compose up -d master slave1 slave2
# 主容器
# GRANT REPLICATION SLAVE ON *.* to 'backup'@'%' identified by 'backup';
# flush master;
docker-compose exec master /bin/bash
mysql -u root -p < docker-entrypoint-initdb.d/init.sql
# 从容器
# stop slave;
# flush slave;
# CHANGE MASTER TO MASTER_HOST='master', MASTER_PORT=3306, MASTER_USER='backup', MASTER_PASSWORD='backup';
# START SLAVE;
# 从容器1
docker-compose exec slave1 /bin/bash
mysql -u root -p < docker-entrypoint-initdb.d/init.sql
# 从容器2
docker-compose exec slave2 /bin/bash
mysql -u root -p < docker-entrypoint-initdb.d/init.sql
```