2

I know to check the Galera cluster status, the command that should be used after login to the mysql client is:

SHOW STATUS LIKE 'wsrep%';

but, how to get the output directly from the command line?

The command below result in error:

[root@mariadb01 ~]# mysql -u root -p "SHOW STATUS LIKE 'wsrep%';"
Enter password:
ERROR 1049 (42000): Unknown database 'SHOW STATUS LIKE 'wsrep%';'

I plan to create a simple monitoring using cron and bash, thus the requirement to get the output using command line

1 Answers1

7

After browsing the website http://www.fromdual.com/making-haproxy-high-available-for-mysql-galera-cluster , I found my own answer.

The answer to monitor Galera cluster status from command line is this command:

# mysql -u root -p<your_password> --exec="SHOW STATUS LIKE 'wsrep%';"

Example:

[root@mariadb01 ~]# mysql -u root -p<your_password> --exec="SHOW STATUS LIKE 'wsrep%';" |grep wsrep_local_state_comment
wsrep_local_state_comment       Synced
  • 1
    After running your example, I noticed the following message --> Info: Using unique option prefix 'exec' is error-prone and can break in the future. Please use the full name 'execute' instead. It might be better to use mysql -u root -p --execute="SHOW STATUS LIKE 'wsrep%';" – Osh Mansor Jul 14 '17 at 13:18
  • Things might have change from the time I found the solution. Thanks for mentioning about the message. – Sharuzzaman Ahmat Raslan Jul 22 '17 at 16:50