本文绝对干货,我们将分享一个shell,他的作用是能够自动恢复mysql主从错误,让你想象不到的强大,想用的朋友直接复制吧,本shell的功能是自动恢复mysql主从错误,是不是感觉非常强大?好吧,直接上代码:
- #!/bin/sh
- # check_mysql_slave status
- ip=eth0
- mysql_command=/home/server/mysql/bin/mysql
- mysql_user=root
- mysql_pass=123456
- mysql_sockfile=/tmp/mysql.sock
- datetime=`date +"%Y-%m-%d_%H:%M:%S"`
- mysql_slave_logfile=/home/server/logs/check_mysql_slave.log
- slave_ip=`ifconfig $ip|grep "inet addr" | awk -F[:" "]+ '{print $4}'`
- #status=$($mysql_command -u$mysql_user -p$mysql_pass -S $mysql_sockfile -e "show slave status/G" | grep -i "running")
- Slave_IO_Running=`grep Slave_IO_Running $mysql_slave_logfile| awk ' {print $2}'`
- Slave_SQL_Running=`grep Slave_SQL_Running $mysql_slave_logfile | awk '{print $2}'`
- if [ "$Slave_IO_Running" = "Yes" -a "$Slave_SQL_Running" = "Yes" ]
- then --Vevb.com
- echo "Slave is Running!"
- else
- echo " $datetime $slave_ip Slave is not running!" >> $mysql_slave_logfile
- cat | $mysql_command -u$mysql_user -p$mysql_pass -S $mysql_sockfile << EOF
- stop slave;
- SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
- start slave;
- exit
- EOF
- fi
新闻热点
疑难解答