时间:2021-07-01 10:21:17 帮助过:3人阅读
#!/bin/bash
port=`netstat -ntl |grep 3306 |wc -l`
process=`ps -ef |grep mysql |grep -v grep |wc -l`
if [ $port -eq 1 ] && [ $process -eq 2 ]
then
echo "MySQL is running"
else
/etc/init.d/mysqld start
fi
2、使用客户端登陆MySQL执行命令,查看返回结果测试服务是否启动,理论上此方法最可靠。
#!/bin/bash
mysql -uroot -p123456 -e "select version();" &> /dev/null
If [ $? -ne 0 ]
then
/etc/init.d/mysqld start
else
echo "MySQL is running"
fi
监控MySQL服务是否正常
标签:mysql