Created
April 17, 2015 01:33
-
-
Save tonyvu2014/83cdc9a5cbf49a7a2c9e to your computer and use it in GitHub Desktop.
Mysql replication monitor and recovery. Set up the cronjob on mysql server (slave side) to run this script daily or weekly to monitor and recover from mysql replication failure. If there is any error an notification email will be sent to the email of your choice.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USER=<your mysql username> | |
PASSWORD=<your mysql password> | |
SUBJECT="Mysql Replication Problem" | |
EMAIL=<your monitor email> | |
RESULT=`mysql -u$USER -p$PASSWORD -e 'show slave status\G' | grep Last_SQL_Error | sed -e 's/ *Last_SQL_Error: //'` | |
if [ -n "$RESULT" ]; then | |
echo "$RESULT" | mail -s "$SUBJECT" $EMAIL | |
mysql -u$USER -p$PASSWORD -e "STOP SLAVE;" | |
mysql -u$USER -p$PASSWORD -e "SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;" | |
mysql -u$USER -p$PASSWORD -e "START SLAVE;" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment