心海恋歌 发表于 2018-8-27 09:17:30

shell脚本检测mysql是否启动的方法

  (1)端口检测
  # netstat -lntup |grep 3306|wc -l
  1
  #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
  #此方法最准确

页: [1]
查看完整版本: shell脚本检测mysql是否启动的方法