share一個自動跳mysql從庫上1062錯誤的腳本
從庫突然掉電可能會導致log里的信息沒flush到硬盤,于是從庫啟動之后主從會因為1062(主鍵重復)而卡住,這里提供一個自動跳1062的腳本
[plain]
#!/bin/sh
MYSQL=mysql
lastPos=0
while [ 1 ]; do
$MYSQL -uroot -e "show slave status/G" > /tmp/.skip
lastError=`cat /tmp/.skip|grep "Last_SQL_Errno"|awk '{print $2}'`
nowPos=`cat /tmp/.skip|grep "Exec_Master_Log_Pos"|awk '{print $2}'`
if [ $lastError -eq 1062 ]; then
if [ $lastPos -ne $nowPos ]; then
echo "blocked, skip one"
$MYSQL -uroot -e "slave stop; set global sql_slave_skip_counter =1; slave start;"
lastPos=$nowPos
else
echo "sleep one second"
sleep 1
fi
elif [ $lastError -eq 0 ]; then
secondsBehind=`cat /tmp/.skip|grep "Seconds_Behind_Master"|awk '{print $2}'`
if [ $secondsBehind -eq 0 ]; then
echo "done"
break
else
echo "$secondsBehind seconds behind server"
sleep 3
fi
else
echo "error $lastError found"
break
fi
done
bitsCN.com聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com