Shell scripts monitor MySQL services and shell scripts monitor mysql
The main content of this article describes how to monitor whether the MySQL service is normal by using shell scripts. For more information, see
The general idea is to check whether the MySQL service is normal: Check whether port 3306 is started, ps to check whether the mysqld process is started, and run the command line to log on to mysql to execute the statement and return the result, php or jsp program detection (developers need to develop programs) and so on;
Method 1: Listen to port 3306
Method 2: view the mysqld Process
Note: If you use process filtering, if the script name contains mysql, script execution is pitfall. Remember !!! The result is inaccurate because the script is grep once;
The execution result is as follows:
Method 3: The mysql service is normal only when both processes and ports are successful.
Method 4: Use the client to log on to mysql and run the command to check whether the returned result Test Service is started. Theoretically, this method is the most reliable.
The execution result is as follows:
[Root @ localhost baby] # sh check_db_client.sh
MySQL is running
The above are four ways for shell scripts to monitor whether the MySQL service is normal. I hope this will be helpful for your learning.