Take you easily to a script _ MySQL-MySQL tutorial for detecting the mysql status

Source: Internet
Author: User
Tags mysql tutorial
This article will show you how to easily access a script for detecting the MySQL status. This article will show you how to easily access a script for detecting the MySQL status. it uses the namp scanning tool. therefore, if the nmap scanning tool is not installed in the system, you must first install the tool.

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 should we kill the process and resume it normally? It is because mysql cannot be shut down normally and cannot be restarted normally. Therefore, it is safe to kill the process and then start the service.


(#! /Bin/bash/usr/bin/nmap localhost | grep 3306if [$? -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/nullfielse/usr/local/mysql/bin/mysqld_safe -- user = mysql &>/dev/nullfi

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.