Home  >  Article  >  Database  >  轻松接触一个检测MySQL状态的脚本

轻松接触一个检测MySQL状态的脚本

PHP中文网
PHP中文网Original
2017-03-31 16:15:131161browse

下面的这个脚本用到了namp扫描工具,所以,系统中如果没安装nmap扫描工具的,需要先安装该工具。
  脚本的功能:
  首先,检测mysql端口是否正常存在,端口不存在就执行启动mysql服务,当然,启动的脚本的位置根据你的安装路径会有不同,然后如果端口存在,则有mysql服务在运行,那么检测mysql状态,能不能正常连接,如能正常连接说明mysql正常,不做任何处理,如果不能正常连接,则杀掉所有mysql进程,然后启动mysql服务,为什么要杀掉进程而不进行正常的重起呢,是因为有时候mysql是不能正常关闭的,所以不能正常重起,所以保险的做法是杀掉进程,然后启动服务。(

  #!/bin/bash
  /usr/bin/nmap localhost |grep 3306
  if [ $? -eq 0 ]
  then
  /usr/local/mysql/bin/mysql -uxxxxx -pxxxxxx --connect_timeout=5 -e "show databases;"
  if [ $? -ne 0 ]
  then
  /bin/photoshop/ target=_blank class=infotextkey>ps aux |grep mysql |grep -v grep | awk '{print $2}' | 
  xargs kill -9
  /usr/local/mysql/bin/mysqld_safe --user=mysql & > /dev/null
  fi
  else
  /usr/local/mysql/bin/mysqld_safe --user=mysql & > /dev/null
  fibitsCN.com

 以上就是轻松接触一个检测MySQL状态的脚本的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn