Home > Database > Mysql Tutorial > body text

一个检测MySQL状态的脚本_MySQL

WBOY
Release: 2016-06-01 14:00:57
Original
1090 people have browsed it

脚本的功能:

  首先,检测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/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
  fi

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!