Run Master-Slave MySQL DB and Cope with emergency with robust scripts.
To Start DB or do recovery process must be simple.
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
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
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
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.