[root@mariadb01 ~]# cat check_mysql.sh
MYSQL=/usr/bin/mysql
MYSQL_HOST=localhost
MYSQL_USER=root
MYSQL_PASSWORD=123456
$MYSQL -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASSWORD -e "show status;" >/dev/null 2>&1
#$mysqlclient --host=$host --port=$port --user=$user --password=$password -e "show databases;" > /dev/null 2>&1
if [ $? == 0 ]
then
echo " $host mysql login successfully "
systemctl start keepalived
exit 0
else
echo " $host mysql login faild"
systemctl stop keepalived
exit 2
fi
转载于:https://blog.51cto.com/wsw26/2067195