Setting up an InnoDB Cluster With a Few Lines of Code

Setting up an InnoDB ClusterIn this day and age, large enterprise companies make use of Ansible, Puppet, or Chef to provision MySQL servers, be it replica sets or clusters. This eases the burden of deployment and workflow management.

However, for some smaller companies, the learning curve hampers the immediate adoption of automation software. This is where the MySQL Shell helps, by allowing you to deploy an N-node InnoDB Cluster or ReplicaSet in less than 60 lines of code.

The Requirements

  • Percona Server for MySQL version 8.0.17 or later, preferable version 8.0.19, each node started as standalone servers
  • Percona MySQL Shell 8.0 or equivalent upstream version
  • MySQL root user and password or equivalent user with grant option
  • Hostname configured on each node, can be done with /etc/hosts

Execute the script and supply the data it needs:

After this, the script will do the rest of the process to configure the 3-node InnoDB cluster and you will just have to wait until it completes.

Here we can see each node is configured by the dba.configureInstance() function. We’re also creating the clusterAdmin user and password at this stage.

At this stage, the InnoDB Cluster is initialized from the first node. At this point the script executes the dba.createCluster() function.

The next step would be to add the other two instances to the cluster. As you will see it uses the CLONE plugin to copy the data from the first node. Here we use the <Cluster>.addInstance() function to add each instance to the cluster.