https://github.com/patternhelloworld/docker-my-sql-replica
Run MySQL Master Slave replication and cope with emergency with Docker and robust scripts
https://github.com/patternhelloworld/docker-my-sql-replica
backup docker docker-compose high-availability mysql mysql-replication mysql8 replication sql
Last synced: 3 months ago
JSON representation
Run MySQL Master Slave replication and cope with emergency with Docker and robust scripts
- Host: GitHub
- URL: https://github.com/patternhelloworld/docker-my-sql-replica
- Owner: patternhelloworld
- Created: 2022-02-23T14:43:55.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-04T15:14:01.000Z (over 2 years ago)
- Last Synced: 2024-10-15T04:02:29.927Z (about 1 year ago)
- Topics: backup, docker, docker-compose, high-availability, mysql, mysql-replication, mysql8, replication, sql
- Language: Shell
- Homepage:
- Size: 129 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Docker-My-SQL-Replica
> Run Master-Slave MySQL DB and Cope with emergency with robust scripts.
To Start DB or do recovery process must be [simple](https://github.com/Andrew-Kang-G/my-sql-replica).
## How to Start
Run this simply after coordinating some values on .env.example
```
$ cd 8.0
$ cp -a .env.example .env
# What to set '.env' ?
## [Security] Set values for 'MYSQL_ROOT_PASSWORD', 'MYSQL_REPLICATION_USER_PASSWORD_MASTER'
## [Safety] Consider setting the following 8 variables to be outside the project root.
## MYSQL_..._PATH_...=./master/data
$ bash run-replica.sh
```
## Emergency Recovery Mode (.env)
When the Slave DB is corrupted, this mode removes all its data and points it back to the Master DB automatically.
```
SLAVE_EMERGENCY_RECOVERY=true
## The mode is currently working in case of "SEPARATED_MODE=false"
SEPARATED_MODE=false
```
## Separated Mode (.env)
The mode is for Master & Slave to be deployed on each instance. Make sure firewalls are open on your network layer. All the commands that you should run and .envs are the same for both Master and Slave.
- .env
```
# Example
SEPARATED_MODE=true
SEPARATED_MODE_WHO_AM_I=master
SEPARATED_MODE_MASTER_IP=172.27.0.20
SEPARATED_MODE_MASTER_PORT=3506
SEPARATED_MODE_SLAVE_IP=172.27.0.58
SEPARATED_MODE_SLAVE_PORT=3507
```
- Master
```
$ cd 8.0
$ cp -a .env.example .env
$ bash run-replica.sh
```
- Slave
```
$ cd 8.0
$ cp -a .env.example .env
$ bash run-replica.sh
```
## Reference
Replication in MySQL relies on the two servers beginning with an identical set of data, after which, every query that it is modifies data on the master makes the same changes to the data on the slave.