共计 1248 个字符,预计需要花费 4 分钟才能阅读完成。
#!/bin/bash
MYSQL=/usr/bin/mysql
MASTER_LOG_FILE="mysql-bin.000002"
MASTER_LOG_POS="154"
MYSQL_PASS="MDV6LnHh."
if [ ! -e $MYSQL ] || [ ! -x $MYSQL ];then
echo " mysql binary does't exist" ; echo " mysql binary does't exist"
exit 1
fi
read -p "Please Input Master IP address: " MASTER_IP
if ! echo "" | nc -v -w 3 $MASTER_IP 3306 &> /dev/null;then
echo "Error : Connect to $MASTER_IP 3306 (tcp) failed: Connection refused"
exit 1
fi
if cat /anchnet/passwd.txt | grep "Slave Status:OK" &> /dev/null ;then
echo "Error : Slave already exists !!!"
exit 1
fi
${MYSQL} -p${MYSQL_PASS} -e "show databases;" --connect-expired-password &> /dev/null
if [ $? != 0 ];then
read -p "Please Input MySQL Password: " MYSQL_PASS
fi
read -p "Please Input User Repl Password: " REPL_PASS
${MYSQL} -h${MASTER_IP} -urepl -p${REPL_PASS} -e "show databases;" --connect-expired-password &> /dev/null
if [ $? != 0 ];then
echo ""
echo "Error : Master repl password error! To the master see /anchnet/passwd.txt"
exit 1
fi
REPL_SQL="CHANGE MASTER TO MASTER_HOST=\"$MASTER_IP\", MASTER_USER=\"repl\", MASTER_PASSWORD=\"$REPL_PASS\",MASTER_LOG_FILE=\"$MASTER_LOG_FILE\",MASTER_LOG_POS=$MASTER_LOG_POS;"
${MYSQL} -p${MYSQL_PASS} -e "$REPL_SQL" --connect-expired-password
if [ $? = 0 ];then
${MYSQL} -p${MYSQL_PASS} -e "start slave;" --connect-expired-password
echo "Slave create successed"
echo "Slave Status:OK" >> /anchnet/passwd.txt
else
echo "Slave create failed"
fi
正文完