Easy access to a script for detecting MySQL status

Source: Internet
Author: User

The following script uses the namp scanning tool. Therefore, if the nmap scanning tool is not installed in the system, you must first install the tool.
Script functions:

First, check whether the mysql port exists normally. If the port does not exist, start the mysql service. Of course, the script to be started is located in a different path according to your installation path. If the port exists, if the mysql service is running, check the mysql status and whether the connection is normal. If the connection is normal, mysql is normal and no processing is performed. If the connection fails, all mysql processes are killed, then, start the mysql service. Why do we need to kill the process and resume it normally? Sometimes mysql cannot be shut down normally, so it cannot be restarted normally. Therefore, it is safe to kill the process, then start the service. (

#! /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 Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.