Skip to main content

Your submission was sent successfully! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates from Canonical and upcoming events where you can meet our team.Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

Charmed MySQL Tutorial > 3. Scale your replicas

Scale your replicas

In this section, you will learn to scale your Charmed MySQL by adding or removing juju units.

The Charmed MySQL operator uses MySQL InnoDB Cluster for scaling. It is built on MySQL Group Replication, providing features such as automatic membership management, fault tolerance, and automatic failover.

An InnoDB Cluster usually runs in a single-primary mode, with one primary instance (read-write) and multiple secondary instances (read-only).

Disclaimer: This tutorial hosts replicas all on the same machine. This should not be done in a production environment.

To enable high availability in a production environment, replicas should be hosted on different servers to maintain isolation.

Summary


Currently, your deployment has only one juju unit, known in juju as the leader unit. For each MySQL replica, a new juju unit (non-leader) is created. All units are members of the same database cluster.

Add replicas

You can add two replicas to your deployed MySQL application with:

juju add-unit mysql -n 2

You can now watch the scaling process in live using: juju status --watch 1s. It usually takes several minutes for new cluster members to be added.

You’ll know that all three nodes are in sync when juju status reports Workload=active and Agent=idle:

Model     Controller  Cloud/Region         Version  SLA          Timestamp
tutorial  overlord    localhost/localhost  3.5.2    unsupported  23:33:55+01:00

App    Version          Status  Scale  Charm  Channel     Rev  Exposed  Message
mysql  8.0.32-0ubun...  active      3  mysql  8.0/stable  147  no

Unit      Workload  Agent  Machine  Public address  Ports  Message
mysql/0*  active    idle   0        10.234.188.135         Primary
mysql/1   active    idle   1        10.234.188.214
mysql/2   active    idle   2        10.234.188.6

Machine  State    Address         Inst id        Series  AZ  Message
0        started  10.234.188.135  juju-ff9064-0  jammy       Running
1        started  10.234.188.214  juju-ff9064-1  jammy       Running
2        started  10.234.188.6    juju-ff9064-2  jammy       Running

The maximum number of Charmed MySQL units in a single Juju application is 9. This is a limitation of MySQL Group replication. Read more about all limitations in the official MySQL documentation.

Remove replicas

Removing a unit from the application scales down the replicas.

Before we scale down, list all the units with juju status. You will see three units: mysql/0, mysql/1, and mysql/2. Each of these units hosts a MySQL replica.

To remove the replica hosted on the unit mysql/2 enter:

juju remove-unit mysql/2

You’ll know that the replica was successfully removed when juju status --watch 1s reports:

Model     Controller  Cloud/Region         Version  SLA          Timestamp
tutorial  overlord    localhost/localhost  3.5.2    unsupported  23:46:43+01:00

App    Version          Status  Scale  Charm  Channel     Rev  Exposed  Message
mysql  8.0.32-0ubun...  active      2  mysql  8.0/stable  147  no

Unit      Workload  Agent  Machine  Public address  Ports  Message
mysql/0*  active    idle   0        10.234.188.135         Primary
mysql/1   active    idle   1        10.234.188.214

Machine  State    Address         Inst id        Series  AZ  Message
0        started  10.234.188.135  juju-ff9064-0  jammy       Running
1        started  10.234.188.214  juju-ff9064-1  jammy       Running

Next step: 4. Manage passwords

Last updated 15 days ago. Help improve this document in the forum.