如果MySQL Master Master复制工作正常,请检查脚本
这篇简短的文章解释了如何使用一个简短的脚本来检查你的MySQL master master复制是否按预期工作。
首先添加一个名为“check”的用户与以下mysql查询:
CREATE USER 'check'@'localhost' IDENTIFIED BY 'YOURPASSWORD';
GRANT SUPER , REPLICATION CLIENT ON * . * TO 'check'@'localhost' IDENTIFIED BY 'YOURPASSWORD' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
然后将此bash脚本添加到/ root目录
。 如果需要,将它添加到您的crontab中:
#!/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ###check if already notified### cd /root if [ -f slave_problem.txt ]; then exit 1; fi ###Check if slave running### ( echo "show slave status \G;" ) | mysql -u check -pYOURPASSWORD 2>&1 | grep "Slave_IO_Running: No" if [ "$?" -ne "1" ]; then echo "Replication failed" > /root/slave_problem.txt fi ###Send notification if replication down### cd /root if [ -f slave_problem.txt ]; then mail -s "Replication problem" admin@example.com < /root/slave_problem.txt fi