(1)端口检测
# netstat -lntup |grep 3306|wc -l

                                                       #1表示mysql已开启,0表示关闭

#!/bin/bash
port=`netstat -intup |grep 3306|wc -l`
if [ $port -ne 1 ]
then
 /etc/init.d/mysqld start
else
 echo "Mysql is running"
fi

(2)是否显示mysql版本
#!/bin/bash
mysql -uroot -p密码 -e "select version();"
if [ $? -ne 0 ]
then
 /etc/init.d/mysqld start
else
 echo "Mysql is running!!!"
fi
#此方法最准确