The MySQL development team recently made a new labs release of the Group Replication plugin for MySQL Server. This is a preview of a new plugin that adds virtually synchronous replication with support for multi-master or active/active update-anywhere replication groups to the already strong lineup of native replication options in MySQL.
Docker is a great fit for this kind of dynamic, multi instance MySQL setup, and containerization is in general a very convenient way to try out new technologies and prototype new solutions. So we created a Docker image based on MySQL Server 5.7.14 that has the Group Replication plugin enabled and ready for use. In this blog post, we’ll provide a short overview of the advantages introduced by Group Replication, and show you how to get started using the new Docker image.
MySQL Group Replication
The most common way to use MySQL replication up to this point has been in a master-slave configuration. Group Replication, on the other hand, implements a multi-master update-everywhere replication protocol. The servers form a replication group where the members interact with each other through message passing. Each member can execute database transactions independently, but read/write transactions must be be coordinated within the group before the transactions get committed. Committed transactions are then broadcast to the rest of the group for the members to apply the changes in the correct order. This ensures consistency across the replication group.
In short, Group Replication allows you to move from a stand-alone MySQL instance to a distributed, highly available MySQL service where individual machines and/or MySQL instances can fail or be taken offline for maintenance and where additional server capacity can be added, all while the distributed MySQL service continues to operate and handle application traffic.
A visit to the MySQL High Availability Blog is highly recommended for more background on Group Replication.
The Group Replication Docker Image
So how do we get going with Group Replication?
As we already observed, a MySQL Group Replication setup is distributed and flexible; the number of servers may shrink or grow as capacity and maintenance needs dictate, and this makes for a very good fit with Docker. We’ve therefore created a Docker image that bundles the labs release of MySQL with the Group Replication plugin. However, do note that the Group Replication plugin is currently in beta, and it shouldn’t be used for production purposes at this stage.
The new image makes setting up Group Replication quite easy. In the following example, we’ll set up a replication group consisting of three MySQL Docker containers named node1–3.
The Group Replication plugin requires the group members to be on the same network subnet, so we start off by creating a Docker network named group1
that we will have our containers connect to:
docker network create group1
The next step is to set up and add members to our replication group, taking care to set a unique replication ID for each member by using the server-id
option. In our Docker image, server-id=1
is special. On first startup, this particular MySQL server instance will be put in a mode where it will serve group configuration information to the other servers that subsequently join the replication group, effectively providing a bootstrap service to the group.
docker run -d --name=node1 --net=group1 -e MYSQL_ROOT_PASSWORD=aTestPwd -e MYSQL_REPLICATION_USER=rpl_user -e MYSQL_REPLICATION_PASSWORD=rpl_pass mysql/mysql-gr --group_replication_group_seeds='node2:6606,node3:6606' --server-id=1
This will set up a separate user account for replication, as specified by the MYSQL_REPLICATION_USER
and MYSQL_REPLICATION_PASSWORD
environment variables. Do note that these are insecure credentials: please refer to the section on Secure Container Startup in the MySQL Docker image documentation for secure alternatives.
We now proceed to start the two remaining nodes, adjusting the node names, server IDs and seed options accordingly:
docker run -d --name=node2 --net=group1 -e MYSQL_ROOT_PASSWORD=aTestPwd -e MYSQL_REPLICATION_USER=rpl_user -e MYSQL_REPLICATION_PASSWORD=rpl_pass mysql/mysql-gr --group_replication_group_seeds='node1:6606,node3:6606' --server-id=2
and
docker run -d --name=node3 --net=group1 -e MYSQL_ROOT_PASSWORD=aTestPwd -e MYSQL_REPLICATION_USER=rpl_user -e MYSQL_REPLICATION_PASSWORD=rpl_pass mysql/mysql-gr --group_replication_group_seeds='node1:6606,node2:6606' --server-id=3
You should now have a running replication group consisting of three MySQL instances.
With that, here’s hoping that you’ll want to try out MySQL Group Replication and that you will find the Docker path to be an easy way to start exploring an exciting new MySQL feature. If you encounter issues or have suggestions for improvements or just want to comment, please either drop us a line in the comments section below or file a bug in the MySQL bug database (either in the “Group Replication” or the “MySQL Package Repos and Docker Images” category).