Home > Database > Mysql Tutorial > body text

Introducing a script to detect MySQL status

巴扎黑
Release: 2017-03-19 10:43:58
Original
1235 people have browsed it

[Introduction] The following script uses the namp scanning tool, so if the nmap scanning tool is not installed in the system, you need to install it first. Function of the script: First, detect whether the mysql port exists normally. If the port does not exist, start the mysql service. Of course, the location of the startup script is

. The following script uses the namp scanning tool, so if If the nmap scanning tool is not installed, you need to install it first.
 Function of the script:

First, check whether the mysql port exists normally. If the port does not exist, start the mysql service. Of course, the location of the startup script will depend on your installation path. If there is a difference, then if the port exists, there is a mysql service running, then check the mysql status to see if it can connect normally. If it can connect normally, it means mysql is normal, and no processing will be done. If it cannot connect normally, kill all mysql processes. Then start the mysql service. Why do you want to kill the process and not restart it normally? Because sometimes mysql cannot be shut down normally, so it cannot be restarted normally, so the safest way 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 $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

The above is the detailed content of Introducing a script to detect MySQL status. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template