MYSQL Slave开机启动脚本

MYSQL做数据库主从时,从库的Slave默认是不启动的。

1、新建脚本mysql-slave-start.sh

#!/bin/sh
user=root
password="123456"
mysql -u$user -p$password -e "show slave statusG;" | grep -i running > slavestatus.log

if [ `cat slavestatus.log | grep -i IO | awk '{print $2}'` = Yes ];
  then
     echo "slave Io process is OK"
  else
     mysql -u$user -p$password  -e "stop slave;"
     wait;
     mysql -u$user -p$password  -e "start slave;"
     wait;
     echo "`date` IO slave has started" >> slavemon.log
fi

if [ `cat slavestatus.log | grep -i SQL | awk '{print $2}'` = Yes ];
   then
     echo "slave SQL process is OK"
   else
     mysql -u$user -p$password  -e "stop slave;"
     wait;
     mysql -u$user -p$password  -e "start slave;"
     wait;
     echo "`date` SQL slave has started" >> slavemon.log

2、赋予可执行权限

chmod +x mysql-slave-start.sh

3、加入开机启动

vim /etc/rc.local

# 追加到末尾即可
/root/start-up/mysql-slave-start.sh

配置完毕!

欢迎关注我的公众号:云栖语,不一样的研发视界。
云栖语微信公众号:change-1978
原文地址:https://www.cnblogs.com/hunttown/p/14861564.html