Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Script sharing that detects mysql status

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "script sharing for detecting mysql status". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

#!/ bin/bash/usr/bin/nmap localhost |grep 3306if [ $? -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/nullfielse/usr/local/mysql/bin/mysqld_safe --user=mysql & > /dev/nullfi

This script uses the namp scanning tool, so if you don't have the nmap scanning tool installed on your system, you need to install it first.

A brief description of the script's functionality:

First of all, check whether the mysql port exists normally, if the port does not exist, start the mysql service. Of course, the location of the script to start will be different according to your installation path. Then if the port exists, there is a mysql service running, then check the mysql status, can you connect normally, if you can connect normally, mysql is normal, do not do any processing, if you cannot connect normally, kill all mysql processes, and then start the mysql service. Why kill the process without restarting it normally? Because sometimes mysql is unable to shut down properly, it cannot restart properly, so the safe approach is to kill the process and then start the service.

The content of "script sharing for detecting mysql status" is introduced here. Thank you for reading it. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report