mariadb-server syntax error
Matthew Barrera
I am writing a bash script and having trouble with $PASSWORD. Can anyone please tell me the correct way to write sql lines in bash script?
QUERY="GRANT ALL PRIVILEGES ON db.* TO 'user'@'localhost' IDENTIFIED BY $PASSWORD;"
SQL="${QUERY1}"
mysql -uroot -p$PASSWORD -hlocalhost -e "$SQL"I would appreciate if someone correct my approach rather suggesting another.
41 Answer
You forgot to quote the password in the query and you assigned non-existing QUERY1 variable to SQL. This should work:
QUERY="GRANT ALL PRIVILEGES ON db.* TO 'user'@'localhost' IDENTIFIED BY '$PASSWORD';"
mysql -uroot -p$PASSWORD -hlocalhost -e "$QUERY" 1