Setting up a MySQL InnoDB Cluster on Oracle Cloud Infrastructure (OCI) using Terraform allows you to automate the deployment of a highly available, self-healing MySQL environment. The InnoDB Cluster offers features such as native high availability, automatic failover, and built-in group replication, making it ideal for production-grade database deployments.
Using Terraform, Oracle's recommended Infrastructure as Code (IaC) tool, simplifies and standardizes the provisioning of cloud resources. It ensures repeatable, version-controlled, and scalable deployments.
In this blog post, I will provide a step-by-step guide on setting up a three-node MySQL InnoDB Cluster on Oracle Cloud Infrastructure (OCI). This setup includes a Bastion host where the MySQL Router is deployed to load balance application connections to the clustered database.
Pre-requisites
The following requirements are needed to set up the InnoDB Cluster
Step 1: Add your API key by using the steps below.
Step 2 Terraform Installation
$ wget https://releases.hashicorp.com/terraform/0.13.4/terraform_0.13.4_linux_amd64.zip
$ unzip terraform_0.13.4_linux_amd64.zip
$ terraform version
$ git clone https://github.com/lefred/oci-mysql-idc.git
$ cd oci-mysql-idc
$ cp terraform.tfvars.template terraform.tfvars
Replace the following based on your OCI environment and requirement:
-- tenancy_ocid, user_ocid, fingerprint, private_key_path, region
--compartment_ocid,ssh_authorized_keys_path, ssh_private_key_path,
clusteradmin_password,, cluster_name, number_of_nodes & node_shape
Below is my terraform.tfvars file after updating it with the details of my OCI environment.
- Initialize the environment with the command below from the oci-mysql-idc directory.
$ terraform init
$ terraform plan
$ terraform apply
Confirm by responding with “yes” to provision the cluster
After successful provisioning of the MySQL InnoDB cluster, you will see the IP addresses of the cluster nodes and the Bastion/MySQL router server.
Test connectivity to the Bastion and confirm that the router is running.
Connect to the MySQL InnoDB Cluster
Switching from the JavaScript/Pyton interface to the SQL interface
Check InnoDB Cluster Status to confirm the Primary and Secondary Database Instances
$ terraform destroy
Fill out the form below to unlock access to more Eclipsys blogs – It’s that easy!