This repository provides a Docker-based setup for creating a MySQL replication environment with a source (master) and replica (slave) configuration.
It simplifies setting up a MySQL database with replication, making it easy to test and deploy in a local or cloud-based environment.
- ✅ Docker-based: The setup uses
docker-compose.ymlto create a MySQL master-slave replication environment. - ✅ Environment Variables: The configuration is done using environment variables, making it easy to customize the setup.
- ✅ Replication: The master MySQL server is configured to replicate data to the replica MySQL server.
- ✅ Security: The setup uses a separate user for replication, ensuring that the replication process is secure.
- ✅ Easy Deployment: The setup can be easily deployed on a local machine or a cloud-based environment.
- Clone the repository to your master machine and replica machine.
git clone https://github.com/yeszao/mysql-replication-docker.git
- Create
.envfile in the root directory of the repository on both machines.Add the values of the environment variables base on your needs.cd mysql-replication-docker cp docker-compose.yml.example docker-compose.yml - Start the MySQL
mastercontainer on the master machine.docker compose up -d master
- Start the MySQL
slavecontainer on the replica machine.cd mysql-replication-docker docker compose up -d slave
The following environment variables are available for configuration in the .env file:
Master MySQL Server
MASTER_ROOT_PASSWORD: The password for the root user on the master MySQL server.MASTER_EXPOSE_PORT: The port on which the master MySQL server is exposed to host.REPLICATOR_USERNAME: The username for the replicator user on the replica MySQL server.REPLICATOR_PASSWORD: The password for the replicator user on the replica MySQL server.
Replica MySQL Server
SLAVE_ROOT_PASSWORD: The password for the root user on the replica MySQL server.SLAVE_EXPOSE_PORT: The port on which the replica MySQL server is exposed to host.MYSQL_MASTER_HOST: The hostname or IP address of the master MySQL server.MYSQL_MASTER_PORT: The port on which the master MySQL server is listening.REPLICATOR_USERNAME: The username for the replicator user on the replica MySQL server.REPLICATOR_PASSWORD: The password for the replicator user on the replica MySQL server.