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