Mysql Monitor Small script

Source: Internet
Author: User
Tags mysql login

MySQL is a relational database management system developed by the Swedish MySQL AB company, currently owned by Oracle Corporation. MySQL is the most popular relational database management system, and in Web applications MySQL is one of the best RDBMS (relational database Management system: relational databases Management systems) application software. MySQL is an associated database management system that keeps data in separate tables rather than putting all of the data in a large warehouse, which increases speed and increases flexibility. The SQL language used by MySQL is the most commonly used standardized language for accessing databases. MySQL software uses a dual licensing policy, which is divided into community and commercial version, due to its small size, fast, low total cost of ownership, especially the open source, the development of the general small and medium-sized web site to choose MySQL as the site database. Thanks to the performance of its community edition, PHP and Apache make a good development environment.


The following is a small script that you have written, placed in a scheduled task, run every 5 minutes, to monitor whether the database can be connected properly, otherwise, send alarm messages to the DBA administrator mailbox and automatically restart the MySQL service, see as follows:


#!/bin/sh

Host= ' 127.0.0.1 '

Port= ' 3306 '

User= ' Root '

password= ' Root '

mysqlclient= "MySQL"


# Check

$mysqlclient--host= $host--port= $port--user= $user--password= $password-E "show databases;" >/dev/null 2>&1

If [$? = = 0]

Then

echo "$host MySQL login successfully"

Exit 0

Else

echo "$host mysql login faild"

#发邮件报警

Mail-s "$host mysq login Faild" [email protected]

#Restart Mysql

/etc/init.d/mysqld restart

Exit 2

Fi




This article is from the "Square Hill" blog, please be sure to keep this source http://523514.blog.51cto.com/513514/1533942

Related Article

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.