Take you to a script for checking and testing the MySQL status at will _ MySQL

Source: Internet
Author: User
The namp scanning tool is used in the script that checks and tests the MySQL status. if nmap scanning tool is not installed in the system, install it first.

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 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

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.