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

The method to determine whether the MYSQL service is normal or not

2025-02-28 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.

Share To

Database

Wechat

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

12
Report