本文绝对干货,我们将分享一个shell,他的作用是能够自动恢复mysql主从错误,让你想象不到的强大,想用的朋友直接复制吧,本shell的功能是自动恢复mysql主从错误,是不是感觉非常强大?好吧,直接上代码:
- #!/bin/sh
- #check_mysql_slavestatus
- 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"inetaddr"|awk-F[:""]+'{print$4}'`
- #status=$($mysql_command-u$mysql_user-p$mysql_pass-S$mysql_sockfile-e"showslavestatus\G"|grep-i"running")
- Slave_IO_Running=`grepSlave_IO_Running$mysql_slave_logfile|awk'{print$2}'`
- Slave_SQL_Running=`grepSlave_SQL_Running$mysql_slave_logfile|awk'{print$2}'`
- if["$Slave_IO_Running"="Yes"-a"$Slave_SQL_Running"="Yes"]
- then--phpfensi.com
- echo"SlaveisRunning!"
- else
- echo"$datetime$slave_ipSlaveisnotrunning!">>$mysql_slave_logfile
- cat|$mysql_command-u$mysql_user-p$mysql_pass-S$mysql_sockfile<<EOF
- stopslave;
- SETGLOBALSQL_SLAVE_SKIP_COUNTER=1;
- startslave;
- exit
- EOF
- fi