[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
本文转自wsw26 51CTO博客,原文链接:http://blog.51cto.com/wsw26/2067195,如需转载请自行联系原作者