#!/bin/bash DB_PASSWORD="" DB_PASSWORD_LEN="" SQL_RESULT="" SQL_RESULT_LEN="" #use a function to get or set the DB_PASSWORD # ......... DB_PASSWORD_LEN=${#DB_PASSWORD} #According to the length to determine whether the password is empty, use different statements to process if [[ ${DB_PASSWORD_LEN} -eq 0 ]];then SQL_RESULT=${mysql -u ${DB_USER} -e quit 2>&1} else SQL_RESULT=${mysql -u ${DB_USER} -p${DB_PASSWORD} -e quit 2>&1} be #The -p and {DB_PASSWORD} must be next to each other, otherwise you will be prompted to enter the password #If the password is correct, SQL_RESULT_LEN is 0 SQL_RESULT_LEN=${#SQL_RESULT} if[[ ${SQL_RESULT_LEN} -eq 0 ]];then echo "Right Password !" else echo "Wrong Password !" be