7.5 Channels (code)

About

This tutorial presents the code implementation for subchapter "Fixed 'MySQL source - MDS' replication"

Code example

Example code at github repository: https://github.com/MuchTest/MySqlDbSystemExample3

The code will implement (in two parts):

First part:

  • creating a VCN and compartment

  • deploying an OCI instance and provisioning MySQL service

  • creating a MySQL DB System

  • creating an object storage(bucket)

After setting up the /root/.oci/config for object storage, and performing the GTID purging on MDS target, you can create the channel:

Second part :

  • creating the channel by using "terraform apply target"

Changes implemented on the code:

  1. "remote.tf" - MySQL-shell snapd installation has been replaced by installing MySQL-Shell from official repository for enabling Javascript mode (apparently,

2. "mysql.yml" - provided root password

3. "channel.tf" will not be called when deploying the environment. The creation of channel will happen when the dumping/loading data and GTID purging are correctly implemented.

4. "variables.tf" - variables added for configuring the object storage (bucket):

n.b: You need to find the ID of the bucket and add it to the variable bucket_namespace

You can find the namespace with command "oci os ns get"

and of course, create_bucket.tf for creation of the bucket

Folder's content:

First Part

Perform the usual terraform commands: terraform init, terraform plan, terraform apply

After the "terraform apply" you will have created/launched following:

  • a VCN and a compartment

  • an OCI instance on which we provisioned MySQL service (mysqlshellinstance)

  • a MySQL DB System

  • an object storage(bucket)

The created Object storage in OCI UI:

Setting up the /root/.oci/config for object storage

You can find the tutorial, step-by-step, at: Install and Configure OCI CLI

Keep in mind, that now you make the changes for the compartment where the MDS, MySQL source and Object bucket are located. This configuration file /root/.oci/config must exist on the instance that can access the MDS (in our case, it's the instance "MySqlShellInsance"

Performing the GTID purging

a) Dumping data from MySQL source into Bucket

Log in to mysqlshellinstance, and create a database:

Dump data into bucket from mysql-shell:

Now, the bucket has the following "mdsobject" object with contents:

Save file @.json on the mysqlshellinstance:

b) Loading data from Bucket into MySQL DB system

Check if data is loaded, and perform the GTID purging:

Second part

Time to deploy the channel:

If no errors, apply changes:

Check from UI, if channel is active

Go back to mysqlshellinstance, and check status of the slave, via MySQL Client:

Check replication

Now, access MySQL source via MySQL client, and create another database:

... and access once again MDS to see if replication was possible:

Destroy resources

Before destroying the resources, you need to empty the bucket, otherwise you may end up with this kind of error:

Delete pre-authenticated requests:

For deleting pre-authenticated requests from mdsbucket by using the OCI CLI, use the command line:

... and delete the object's contents:

Now, you can apply "terraform destroy"

Code for an architecture with Instance in a public subnet, and MDS in a private subnet, at following github repository: https://github.com/MuchTest/ExampleMySqlDbAndInstance

Fini!

Last updated