How to check Galera Cluster status?

mysql mariadb cluster galera devops linux ubuntu

To check Galera Cluster status, we need to query database with SHOW STATUS statements, for variables regarding cluster:

  1. wsrep_cluster_size
  2. wsrep_local_state_comment

To allow password-less checks for (root) user, we can provide password in ~/.my.cnf file and pass it with --defaults-extra-file parameter to the mysql command.

The .my.cnf file can contain various extra configuration variables, at this case we will store password for root MySQL user (not to confuse with unix root user password) in /root/.my.cnf:

[client]
password=root_password

Storing file in root home directory will prevent reading password by others.

The final status checking bash script for Galera Cluster consists of following code, explained earlier:

#!/bin/bash
sudo mysql --defaults-extra-file=/root/.my.cnf -e "SHOW STATUS LIKE 'wsrep_cluster_size';"
sudo mysql --defaults-extra-file=/root/.my.cnf -e "SHOW STATUS LIKE 'wsrep_local_state_comment';"

The example output of script:

+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 2     |
+--------------------+-------+
+---------------------------+--------+
| Variable_name             | Value  |
+---------------------------+--------+
| wsrep_local_state_comment | Synced |
+---------------------------+--------+

The cluster size in this case i 2 nodes, the state is Synced.