Mariadb-Server Syntax Error

Mariadb-Server Syntax Error

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.

4

1 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.