简体   繁体   中英

How to determine if there is a user in mysql in BASH?

How to determine if there is a user in mysql in BASH ?

if [ "$NAME_USER" == ???? ]; then
  echo "User exists in MySQL"
else
  echo "User no exists in MySQL"
fi
while read User; do
    if [[ "$NAME_USER" == "$User" ]]; then
        echo "$User exists in MySQL"
        break
    fi
done < <(mysql -B -N -e 'use mysql; SELECT `user` FROM `user`;')

if [[ "$NAME_USER" != "$User" ]]; then
    echo "$NAME_USER does not exists in MySQL"
fi

您可以包含一个脚本来进行mysql查询,然后解析输出。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM