检查Mysql主从状态

时间:2022-03-02 01:55:05

.检查MySQL主从同步状态

#!/bin/bash

USER=bak

PASSWD=123456

IO_SQL_STATUS=$(mysql -u$USER -p$PASSWD -e  show slave statusG  |awk -F:  /Slave_.*_Running/{gsub(": ",":");print $0} )  #gsub去除冒号后面的空格

for i in $IO_SQL_STATUS; do

THREAD_STATUS_NAME=${i%:*}

THREAD_STATUS=${i#*:}

if [ "$THREAD_STATUS" != "Yes" ]; then

echo "Error: MySQL Master-Slave $THREAD_STATUS_NAME status is $THREAD_STATUS!"

fi

done