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
-B and -N for mysql so the table header is not included in the output.mysql very often in scripts, but when I do (usually I pipe the output to further process) table headers are excluded...-B, but not -N.xargs to strip the carriage return at the end of each value in $User for this to work.