Easy access to a script that detects MySQL status

Source: Internet
Author: User
Tags mysql access

The following script uses the Namp Scan tool, so if the Nmap Scan Tool is not installed in the system, the tool needs to be installed first.
  Functions of the script:

First of all, detect whether the MySQL port is normal, the port does not exist on the implementation of the start of the MySQL service, of course, the location of the startup script according to your installation path will be different, and then if the port exists, there is a MySQL service running, then detect the MySQL state, can not connect If the normal connection to the normal MySQL, do not do any processing, if not normal connection, then kill all the MySQL process, and then start the MySQL service, why to kill the process without a normal restart it is because sometimes MySQL can not normally shut down, so can not normal restart, So the insurance practice is 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 $} ' 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.