How to Create a MySQL Galera Cluster?

Hasan Coskun
Towards Dev
Published in
2 min readMay 2, 2024

--

MySQL Galera Cluster is an excellent solution for high availability and database workload distribution. In this article, we will provide a step-by-step guide on how to create a MySQL Galera Cluster. Galera Cluster is a distributed database system where several MySQL servers work synchronously to provide database services, ensuring uninterrupted operation even if one server fails.

1. Determining Requirements

Before starting the MySQL Galera Cluster installation, make sure you have the following components:
- At least three MySQL servers
- Three independent IP addresses
- Ensure that each server has the same version of MySQL installed
- A network-accessible port (typically 3306)

2. Installing MySQL and Galera Cluster Software

Follow these steps to install MySQL and Galera Cluster software:
- Installing Mysql

sudo yum update
sudo yum install mysql-server

Installing Galera Cluster Software

wget https://downloads.mariadb.com/MariaDB/mariadb-10.5.12/yum/centos8-amd64/rpms/galera-4-26.4.2.el8.x86_64.rpm

Replace it with the appropriate package for your system and requirements.

To install the downloaded Galera Cluster package, use the following command:

sudo rpm -Uvh galera-4-26.4.2.el8.x86_64.rpm

3. Configuring Galera Cluster

Open the `my.cnf` file on each MySQL server and edit it as follows:

 [mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0

# Galera Cluster Settings
wsrep_on=ON
wsrep_provider=/usr/lib/galera4/libgalera_smm.so
wsrep_cluster_address=gcomm://IP1,IP2,IP3
wsrep_cluster_name=my_cluster
wsrep_node_address=IP_current_node
wsrep_node_name=node1

Replace `IP1`, `IP2`, and `IP3` with the IP addresses of the other MySQL servers. `IP_current_node` is the IP address of your current server.

Save the `my.cnf` file and restart the MySQL service. Repeat these steps for other MySQL servers.

4. Starting Galera Cluster

To start the Galera Cluster, follow these steps:

  1. First, run the `galera_new_cluster` command on one MySQL server.
  2. On other MySQL servers, run the following commands:
systemctl start mysql

Ensure that all servers start successfully.

--

--