Multiple ways to monitor MySQL

Source: Internet
Author: User


Several ways to determine if MySQL is normal

#################################

Method 1: Look at the port

Netstat-lntup|grep 3306|wc-l

Lsof-i: 3306 |wc-l

Remote:

/telnet/nc/nmap

#################################

Method 2: See the process

Ps-ef |grep Mysqld|wc-l

#################################

Method 3: Go to MySQL to see the version

[Email protected] ~]# mysql-uroot-e "select version ();"

+-----------+

| Version () |

+-----------+

| 5.1.72 |

+-----------+

[[email protected] ~]# echo $?

0

[Email protected] ~]#

MYSQL-UROOT-E "select version (); &>1 >>/dev/null; echo $?

#################################

Method 4: Let the development write Java or PHP and other programs to monitor

#################################

Method 5: Use the combination of the monitoring methods above 4


######################################

######################################

Script 1

[email protected] script]# cat mysqlif.sh

#!/bin/sh

port= ' Netstat-lnt|grep 3306|wc-l '

If [$port-ne 1]

Then

echo "MySQL isn ' t running."

/etc/init.d/mysqld start

echo "MySQL is running."

Else

echo "MySQL is running."

Fi

[Email protected] script]#

######################################

######################################

Script 2

[email protected] script]# cat mysqlif.sh

#!/bin/sh

#port = ' Netstat-lnt|grep 3306|wc-l '

Proc= ' Ps-ef |grep mysqld|grep-v grep |wc-l '

If [$proc-lt 1]

Then

echo "MySQL isn ' t running."

/etc/init.d/mysqld start

echo "MySQL is running."

Else

echo "MySQL is running."

Fi

[Email protected] script]#

######################################

######################################

Script 3 Recommended methods

[email protected] script]# cat mysqlif.sh

#!/bin/sh

#port = ' Netstat-lnt|grep 3306|wc-l '

#proc = ' Ps-ef |grep mysqld|grep-v grep |wc-l '

MYSQL-UROOT-E "select version (); &>1 >>/dev/null

#mysql-uroot-ppassword-e "select version (); &>1 >>/dev/null

Num= ' echo $? '

If [$num-ne 0]

Then

echo "MySQL isn ' t running."

/etc/init.d/mysqld start

echo "MySQL is running."

Else

echo "MySQL is running."

Fi

[Email protected] script]#

######################################

######################################

Script 4

[email protected] script]# cat mysqlif.sh

#!/bin/sh

Pidfile=/application/mysql5.1.72/data/lamp.pid

Mysql_path=/application/mysql5.1.72/bin

Datadir=/application/mysql5.1.72/data

if [!-F $pidfile]

Then

$mysql _path/mysqld_safe--datadir= $datadir--pid-file= $pidfile & 2>&1/dev/null

Else

echo "MySQL is running."

Fi

[Email protected] script]#


#################### ###############

Monitoring other services can refer to the above several monitoring methods


Means of monitoring Web services

1. Local: ss, Netstat, lsof

Remote: Telnet, Nmap, NC

2. Number of local processes

Ps-ef |grep XXX

3.curl-s-I see if the return value is 200

Wget


This article is from the "Struggle Bar" blog, please be sure to keep this source http://lvnian.blog.51cto.com/7155281/1701047

Multiple ways to monitor MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.