简体   繁体   English

如何确定BASH中的mysql中是否有用户?

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

How to determine if there is a user in mysql in BASH ? 如何确定BASH中的mysql中是否有用户?

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查询,然后解析输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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