Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

mariadb-server syntax error

Writer 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.

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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