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