Setting Up an InnoDB Cluster in MySQL _ by Makhshif Tanvir _ Medium

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

Open in app Sign up Sign in

Search Write

Setting Up an InnoDB Cluster


in MySQL
Makhshif Tanvir · Follow
3 min read · Dec 19, 2023

InnoDB clusters in MySQL offer high availability and fault


tolerance, ensuring a robust database system. Here’s a step-by-
step guide to set up an InnoDB cluster on multiple VMs:

Connectivity pre-requisite

Make sure the port 3306 and 33061 (or the ports you are using for
database and replication) are allowed between the participating
nodes

1. Install MySQL Server and MySQL Shell:

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 1/12
04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

Install MySQL Server on each VM. Ensure the MySQL versions


are the same:

mysql --version

Install MySQL Shell on all VMs:

yum install mysql-shell

Check the MySQL Shell version on all machines to ensure


uniformity:

mysqlsh -V

2. Configuration for Cluster Connectivity:


Update my.cnf on each VM:

bind_address=0.0.0.0

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 2/12
04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

In MySQL, execute the following queries to enable connections:

UPDATE mysql.user SET host='%' WHERE user='root';


GRANT ALL ON *.* TO root@'%';
systemctl restart mysqld

At this point, all VMs should be able to connect to eachother

mysql -u root -p IP_OF_OTHER_MACHINE

3. Assign Cluster Rights:


Grant specific rights for InnoDB cluster on each VM:

GRANT CLONE_ADMIN, CONNECTION_ADMIN, CREATE USER, EXECUTE, FILE,


GROUP_REPLICATION_ADMIN, PERSIST_RO_VARIABLES_ADMIN, PROCESS, RELOA
REPLICATION CLIENT, REPLICATION SLAVE, REPLICATION_APPLIER,
REPLICATION_SLAVE_ADMIN, ROLE_ADMIN, SELECT, SHUTDOWN, SYSTEM_VARIA
ON *.* TO 'root'@'%' WITH GRANT OPTION

4. Configuration Check and Rectification:


Use MySQL Shell to check instance configurations:

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 3/12
04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

mysqlsh -u root -h IP_OF_PRIMARY


dba.checkInstanceConfiguration('root@1.1.1.1:3306')
dba.checkInstanceConfiguration('root@2.2.2.2:3306')
dba.checkInstanceConfiguration('root@3.3.3.3:3306')

Example output would be something like this

+----------------------------------------+---------------+---------
| Variable | Current Value | Required
+----------------------------------------+---------------+---------
| binlog_transaction_dependency_tracking | COMMIT_ORDER | WRITESET
| enforce_gtid_consistency | OFF | ON
| gtid_mode | OFF | ON
| server_id | 1 | <unique
| slave_parallel_type | DATABASE | LOGICAL_
| slave_preserve_commit_order | OFF | ON
+----------------------------------------+---------------+---------

Rectify configuration issues reported as needed. When


everything is fine, it will show output as :

Checking instance configuration...


Instance configuration is compatible with InnoDB cluster

The instance 'hostname_of_primary:3306' is valid to be used in an I

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 4/12
04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

"status": "ok"
}

5. Cluster Setup:
Login to the primary machine via shell:

mysqlsh -u root -h IP_OF_PRIMARY (i.e 1.1.1.1)

Configure instances on the primary machine:

dba.configureInstance('root@1.1.1.1:3306')

Create the cluster on the primary machine:

cluster = dba.createCluster('devCluster')

Add other instances to the cluster (execute on primary):

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 5/12
04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

cluster.addInstance('root@2.2.2.2:3306')
cluster.addInstance('root@3.3.3.3:3306')

6. Cluster Status Verification:


Check the cluster status:

cluster = dba.getCluster('devCluster')
cluster.status();

Output would be like following:

{
"clusterName": "devCluster",
"defaultReplicaSet": {
"name": "default",
"primary": "hostname_of_primary:3306",
"ssl": "REQUIRED",
"status": "OK_NO_TOLERANCE",
"statusText": "Cluster is NOT tolerant to any failures.",
"topology": {
"hostname_of_primary:3306": {
"address": "hostname_of_primary:3306",
"memberRole": "PRIMARY",
"mode": "R/W",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.25"

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 6/12
04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

},
"hostname_of_secondary:3306": {
"address": "hostname_of_secondary:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"role": "HA",
"status": "ONLINE",
"version": "8.0.25"
}
},
"topologyMode": "Single-Primary"
},
"groupInformationSourceMember": "hostname_of_primary:3306"
}

Verify the cluster status to ensure a successful setup.

Here we have one primary and we added only one secondary


node. It says “Cluster is NOT tolerant to any failures”, When we
add the third instance, this message will disappear since we need
at least 3 nodes for the cluster.

MySQL Innodb Database Administration Cluster Dba

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 7/12
04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

Written by Makhshif Tanvir Follow

3 Followers

Database engineer navigating Oracle, MySQL, PG, MSSQL, Big Data,


MongoDB, DevOPs and automation realms. Crafting efficient data
universes. 🛠️

More from Makhshif Tanvir

Makhshif Tanvir Makhshif Tanvir

Configuring MySQL Router Slave I/O for channel ‘’: Got


and Keepalived for High… fatal error 1236 from master…
High availability is crucial for database This error will come up when the slave
systems to ensure continuous acces… is unable to location the log file or…

Mar 27 3 Dec 25, 2023

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 8/12
04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

Makhshif Tanvir Makhshif Tanvir

Unable to create session How to Reset MySQL Root


channel with nsrexecd. User Lost Password
When executing backups in Dell EMC Losing access to the MySQL root user
NetWorker, encountering errors can… account can be challenging, but…

Jan 12 Dec 19, 2023

See all from Makhshif Tanvir

Recommended from Medium

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 9/12
04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

Data SQL Hector Smith in Towards Dev

SQL Replication and High Setting up a change tracking


Availability system in PostgreSQL
This part covers various SQL How I see what changed, when, and by
replication and high availability… whom

Mar 21 May 28 3

Lists

Staff Picks Stories to Help You


681 stories · 1109 saves Level-Up at Work
19 stories · 678 saves

Self-Improvement 101 Productivity 101


20 stories · 2234 saves 20 stories · 1981 saves

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 10/12
04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

Umangshrestha Alexandra in Towards Dev

A Beginner Guide to Python and PostgreSQL:


PostgreSQL Functions Powerful Combination
Understanding PL/pgSQL Basic Checkout the real power of Python &
SQL

Jun 22 18 Jun 24 139

Hüseyin Tugay Yeşilyurt Alexandra

Optimizing Data Access in Efficient Data Retrieval with


Spring Boot 3 with HAProxy… PostgreSQL…
Optimizing Data Access in Spring PostgreSQL provides powerful
Boot 3 with HAProxy and MySQL:… capabilities for handling JSON data,…

Jan 22 21 Jun 5 68

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 11/12
04/07/2024, 14:24 Setting Up an InnoDB Cluster in MySQL | by Makhshif Tanvir | Medium

See more recommendations

https://medium.com/@makhshif.tanvir/setting-up-an-innodb-cluster-in-mysql-bfdb62f4f9a9 12/12

You might also like