Created
August 16, 2021 14:39
-
-
Save Tinram/7dcffbc22cd04d16b731dd8d1ed5a8e7 to your computer and use it in GitHub Desktop.
GTID replication between two MySQL 8 docker containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Just proof-of-concept GTID replication, no security in the following set-up: | |
$ docker pull mysql | |
# Create Docker containers from offical MySQL image | |
$ docker run --name master -e MYSQL_ROOT_PASSWORD=password -d mysql | |
$ docker run --name replica -e MYSQL_ROOT_PASSWORD=password -d mysql | |
# get docker master container IP: | |
docker inspect master | grep IP | |
# Connect to MySQL containers via Workbench and Docker IP from above | |
# or: | |
$ docker exec -it master /bin/bash # then mysql -u root -p | |
# Binary logging is enabled by default in MySQL 8 (log_bin) | |
# MySQL master container: | |
SET GLOBAL enforce_gtid_consistency = on; | |
SET GLOBAL gtid_mode = off_permissive; # iterate through mode states | |
SET GLOBAL gtid_mode = on_permissive; | |
SET GLOBAL gtid_mode = on; | |
CREATE USER replica@'%' IDENTIFIED BY 'password'; | |
GRANT REPLICATION SLAVE ON *.* TO replica@'%'; | |
# MySQL replica container: | |
SET GLOBAL enforce_gtid_consistency = on; | |
SET GLOBAL server_id = 2; | |
SET GLOBAL gtid_mode = off_permissive; | |
SET GLOBAL gtid_mode = on_permissive; | |
SET GLOBAL gtid_mode = on; | |
CHANGE MASTER TO MASTER_HOST = '<docker master IP>', MASTER_PORT=3306, MASTER_USER='replica', MASTER_PASSWORD='password', MASTER_AUTO_POSITION=1; | |
START SLAVE; | |
# simple test: | |
# master | |
CREATE DATABASE xyz; | |
# replica: | |
SHOW DATABASES; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment