Databases 10 min read

How to Build a Multi‑Node MySQL InnoDB Cluster from Scratch

This step‑by‑step guide explains how to set up a high‑availability MySQL InnoDB Cluster across four Linux servers, covering sandbox testing, installing MySQL, MySQL Shell, and MySQL Router, configuring each node, creating the cluster, adding instances, and connecting clients via the router.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How to Build a Multi‑Node MySQL InnoDB Cluster from Scratch

1. Introduction

InnoDB Cluster setup can be divided into two scenarios:

(1) Experimental environment – use a sandbox to simulate instances, see the previous article and MySQL official documentation.

(2) Real multi‑server node environment – more complex, with limited reference material and several challenges.

The following summarizes the detailed process of building a multi‑node InnoDB Cluster.

2. Goal

Prepare four servers: node01, node02, node03 as cluster nodes, and node04 as the management node that creates the cluster and acts as the router.

Finally, a high‑availability cluster is built, with a router that clients connect to.

3. Architecture Overview

(1) Install base environment

node01, node02, node03 install mysql and mysql-shell.

node04 installs mysql-shell and mysql-router.

(2) Create cluster – on node01 configure MySQL, start it, then from node01 shell run dba.configureLocalInstance(); to make it ready, and from node04 shell run dba.createCluster() to create the cluster.

(3) Add nodes – configure node02 and node03 MySQL, start them, then from node04 shell run dba.addInstance() to add each node.

(4) Use router – start mysql‑router on node04 and let clients connect through it.

4. Detailed Build Steps

(1) Environment Installation

Configure /etc/hosts on each server, e.g.:

192.168.31.13 node03
192.168.31.228 node02
192.168.31.36 node01

Required software:

mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

mysql-shell-1.0.9-linux-glibc2.12-x86-64bit.tar.gz

mysql-router-2.1.3-linux-glibc2.12-x86-64bit.tar.gz

Install each on the respective servers.

1. MySQL

# Extract
 tar zxf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
 mv mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql-5.7
 cd /usr/local

 # Initialize instance
 mkdir data
 mysql-5.7/bin/mysqld --initialize-insecure --basedir=$PWD/mysql-5.7 --datadir=$PWD/data

 # Create mysql user
 groupadd mysql5.7
 useradd -g mysql5.7 mysql5.7
 chown -R mysql5.7:mysql5.7 /usr/local/mysql-5.7
 chown -R mysql5.7:mysql5.7 /usr/local/data

2. Shell

# Extract
 tar zxf mysql-shell-1.0.9-linux-glibc2.12-x86-64bit.tar.gz mysql-shell

3. Router

# Extract
 tar zxf mysql-router-2.1.3-linux-glibc2.12-x86-64bit.tar.gz mysql-router

(2) Create Cluster

Configure node01 MySQL and start it.

Switch to the mysql user: su mysql5.7 Edit my.cnf (e.g., /usr/local/data/my.cnf) with settings such as datadir, basedir, port, server_id=1, GTID mode, etc.

[mysqld]

datadir=/usr/local/data
basedir=/usr/local/mysql-5.7/
port=3306
socket=/usr/local/data/mysql.sock
server_id=1
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW
transaction_write_set_extraction=XXHASH64

Start MySQL:

nohup /usr/local/mysql-5.7/bin/mysqld --defaults-file=data/my.cnf >data/nohup.out 2>&1 &

# Return to root
exit

Login and set the root password:

/usr/local/mysql-5.7/bin/mysql -uroot -h127.0.0.1 --skip-password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'A123456';

Configure the instance with mysql‑shell:

bin/mysqlsh
shell.connect('root@localhost:3306');
dba.configureLocalInstance();

From node04, create the cluster:

bin/mysqlsh
shell.connect('root@node01:3306');
var cluster = dba.createCluster('myCluster');
cluster.status();

(3) Add Instance node02

Configure node02 MySQL and start it.

Edit my.cnf (same as node01 but with server_id=2). server_id=2 Configure with mysql‑shell on node02, then add to the cluster from node04:

bin/mysqlsh
shell.connect('root@localhost:3306');
dba.configureLocalInstance();
# Stop MySQL, edit my.cnf to add:
# group_replication_allow_local_disjoint_gtids_join=ON
# Restart MySQL
# From node04:
cluster.addInstance('root@node02:3306');
cluster.status();

(4) Add Instance node03

Same steps as node02, but set server_id=3 and add with

cluster.addInstance('root@node03:3306');

(5) Install Router

On node04, start mysql‑router:

mysqlrouter --bootstrap root@ic-1:3306 --directory myrouter --name=myrouter
myrouter/start.sh

Clients can now connect to the router.

5. Summary

Download links:

https://dev.mysql.com/downloads/mysql/
https://dev.mysql.com/downloads/shell/
https://dev.mysql.com/downloads/router/

Choose the Linux Generic version for all components.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

mysqldatabase clusteringMySQL RouterMySQL ShellInnoDB Cluster
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.