无限星辰工作室-客户无限互联网动力之源

标题: 定时检查Mysql状态 重启mysql [打印本页]

作者: crx349    时间: 2019-12-2 12:45
标题: 定时检查Mysql状态 重启mysql
脚本:

  1. #!/bin/bash
  2. count=0
  3. #尝试循环10次后退出
  4. while [ $count -lt 10 ]
  5. do
  6. pgrep -x mysqld >/dev/null

  7. if [ $? -ne 0 ];then
  8. count=$[$count+1]
  9. #不能使用service mysqld start,启动不成功
  10. /etc/init.d/mysqld stop
  11. /etc/init.d/mysqld start

  12. else
  13. echo “MySQL server is running .”
  14. break

  15. fi
  16. done

  17. if [ $count -ne 0 ];then
  18. #写入日志文件,不需要可以注释掉
  19. echo -e “At time: ` date "+%Y-%m-%d %H:%M:%S"` :MySQL is stop . Trying to restart $count times .\n” >>/root/sqllog.txt
  20. fi
复制代码

原文链接:https://blog.csdn.net/qq_40622375/article/details/95739034




欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://www.xmspace.net/) Powered by Discuz! X3.4