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