In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the method of judging whether the MYSQL service is normal or not. The content of the article is carefully selected and edited by the author. It has a certain pertinence and is of great significance to everyone's reference. Let's learn about the method of judging whether the MYSQL service is normal or not with the author.
1) Port judgment
[root@localhost ~] # netstat-lntup | grep 3306tcp 0 0 0.0.0.0 lntup 3306 0.0.0.0 LISTEN 2288/mysqld
2) process judgment
[root@localhost ~] # ps-ef | grep mysqld mysql 2071 10 11:32? 00:00:00 / bin/sh / usr/bin/mysqld_safe-- basedir=/usrmysql 2288 2071 0 11:32? 00:00:24 / usr/libexec/mysqld-- basedir=/usr-- datadir=/var/lib/mysql-- plugin-dir=/usr/lib64/mysql/plugin-- log-error=/var/log/mariadb/mariadb.log- -pid-file=/var/run/mariadb/mariadb.pid-- socket=/var/lib/mysql/mysql.sockroot 10097 6962 0 17:27 pts/1 00:00:00 grep-- color=auto mysqld
3) return value judgment
[root@localhost ~] # mysql-uroot-proot-e "select version ();" & > / dev/null [root@localhost ~] # echo $? 0
Method 1: the idea of implementation is to filter out MYSQL port 3306 to judge:
#! / bin/bashport= `netstat-lnt | grep 3306 | wc- l`if [$port-ne 1] then / etc/init.d/mysql startelse echo "MySQL is running." fi execution result: [root@localhost ~] # sh mysql1.sh MySQL is running.
Method 2: the idea of implementation is to judge through the MYSQL process:
#! / bin/bashportcess= `ps-ef | grep mysql | grep-v grep | wc-l`if [$portcess-ne 2] then / etc/init.d/mysqld startelse echo "MySQL is running." fi execution result: [root@localhost ~] # sh mysql1.sh MySQL is running. Note: the filtered string 'mysql'' does not appear in the script name, but not if it does.
Method 3: the realization idea is to judge the return value of the web connection:
#! / bin/bashmysql-uroot-proot-e "select version ();" & > / dev/nullif [$?-ne 0] then / etc/init.d/mysqld startelse echo "MySQL is running." fi execution result: [root@localhost ~] # sh mysql1.sh MySQL is running.
Summary: web service monitoring means:
Port (local or remote)
Local process
Header (httpd code)
URL (wget,curl
After reading the above methods to judge whether the MYSQL service is normal, many readers must have some understanding. If you need more industry knowledge and information, you can continue to follow our industry information column.
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.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.