Skip to content

wagnerjfr/mysql-group-replication-docker-compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Setting up MySQL Group replication with Docker Compose

This repository now provides two separate Docker Compose setups:

  • mysql-8.0/docker-compose.yml for MySQL 8.0 (mysql/mysql-server:8.0)
  • mysql-9.6/docker-compose.yml for MySQL 9.6 (mysql:9.6)

Full article MySQL 8.0

Full article MySQL 9.6

Quickstart

Prerequisite: Docker and Docker Compose installed.

  1. Start the MySQL 9.6 cluster:

    cd mysql-9.6 && docker compose up -d
  2. Wait for all 3 nodes to show Up (healthy):

    docker compose ps
  3. Bootstrap the group (run once on node1):

    docker compose exec node1 mysql -uroot -pmypass \
      -e "SET @@GLOBAL.group_replication_bootstrap_group=ON;" \
      -e "CREATE USER IF NOT EXISTS 'repl'@'%' IDENTIFIED BY 'replpass';" \
      -e "GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';" \
      -e "FLUSH PRIVILEGES;" \
      -e "CHANGE REPLICATION SOURCE TO SOURCE_USER='repl', SOURCE_PASSWORD='replpass' FOR CHANNEL 'group_replication_recovery';" \
      -e "START GROUP_REPLICATION;" \
      -e "SET @@GLOBAL.group_replication_bootstrap_group=OFF;" \
      -e "SELECT * FROM performance_schema.replication_group_members;"
  4. Join node2 and node3 to the group:

    for N in 2 3; do
      docker compose exec node$N mysql -uroot -pmypass \
        -e "STOP GROUP_REPLICATION;" \
        -e "RESET BINARY LOGS AND GTIDS;" \
        -e "CHANGE REPLICATION SOURCE TO SOURCE_USER='repl', SOURCE_PASSWORD='replpass' FOR CHANNEL 'group_replication_recovery';" \
        -e "START GROUP_REPLICATION;"
    done
  5. Verify group membership:

    docker compose exec node1 mysql -uroot -pmypass \
      -e "SELECT MEMBER_HOST, MEMBER_STATE, MEMBER_ROLE FROM performance_schema.replication_group_members;"
  6. Clean up when done:

    docker compose down -v

Full step-by-step explanations for MySQL 8.0 and 9.6 are in the linked articles above.

P.S. Take a look at this tutorial and check how to setup MySQL Group Replication with Docker containers.

About

The below steps show how to setup MySQL Group Replication with Docker Compose using mysql/mysqlserver:8.0 Docker images.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors