1

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

if [ "$NAME_USER" == ???? ]; then
  echo "User exists in MySQL"
else
  echo "User no exists in MySQL"
fi
4

2 回答 2

3
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
于 2012-08-14T21:37:06.360 回答
0

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

于 2012-08-14T20:57:45.177 回答