• notice
  • Congratulations on the launch of the Sought Tech site

A script that detects the MySQL state

The function of the script:

First, check whether the mysql port exists normally, and execute the startup if the port does not exist mysql service, of course, the location of the startup script will be different according to your installation path, and 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 that mysql is normal and do not do any processing.If it cannot connect normally, then kill all mysql processes and then start the mysql service.Why kill the process instead of normal The restart is because sometimes mysql cannot be shut down normally, so it cannot be restarted normally, so the safe 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

Tags

Technical otaku

Sought technology together

Related Topic

1 Comments

author

atorvastatin pills & lt;a href="https://lipiws.top/"& gt;order atorvastatin 20mg pill& lt;/a& gt; generic atorvastatin 20mg

Romcgx

2024-03-07

Leave a Reply

+