檢測mysql密碼是否輸入正確的指令碼代碼

來源:互聯網
上載者:User

MysqlUser='root'

MysqlPassword=''

function CheckMysqlPassword()

{

    if [ -z $MysqlPassword ]

    then

        cmdResult=`mysql -u$MysqlUser -e quit 2>&1`

    else

        cmdResult=`mysql -u$MysqlUser -p$MysqlPassword -e quit 2>&1`

    fi

cmdResultLineCount=`echo $cmdResult | wc -c`

if(( cmdResultLineCount > 1 ))

    then

        printf "Error occurred! \n" #$cmdResult!\n"

    else

        printf "Connect mysql successfully! \n"

    fi

#printf "cmdResult = $cmdResult \n"

#! for more details:

#! ERROR 1045 (28000): Access denied for user 'root'@'localhost'

    AccessDenied=`echo $cmdResult | grep Access.denied | wc -c`

#if (( AccessDenied > 1 ))

    #then

    #    printf "Connect failed, access denied.\n"

    #fi;

#! Can't connect to local MySQL server through socket ...

    #CannotConnect=`echo $cmdResult | grep Can.t.connect | wc -c`

#if (( CannotConnect > 1 ))

    #then

    #    printf "Connect faild, mysql may be not started.\n"

    #fi

}

printf "Please input the password for mysql root user:"

read MysqlPassword

CheckMysqlPassword

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.