判斷GTID複制中從庫有沒有與主庫同步
show slave stautus\G中:
當Retrieved_Gtid_Set = Executed_Gtid_Set 表示從庫已經和主庫完成同步
#!/bin/bash
Exec_num=$(mysql -uroot -p147258 -e "show slave status\G;" 2>/dev/null|grep 'Executed_Gtid_Set'| awk -F":" '{print $3}'|awk -F "-" '{ print $2}'|awk -F"," '{print $1}')
Ret_num=$(mysql -uroot -p147258 -e "show slave status\G;" 2>/dev/null|grep 'Retrieved_Gtid_Set'| awk -F":" '{print $3}'|awk -F "-" '{print $2}')
#判斷這倆個數值是否相同,相等輸出yes,否則no
if [ $Exec_num -eq $Ret_num ]
then
echo "yes"
else
echo "no"
fi