I'm writing a bash script for automatic installation and configuration of a system, and I need to be able to set the root password for mysql from a declared variable in the script, but I can't get it to work.
read -p "Password `echo $'\n> '`" mysql_passwd
mysql --defaults-file=/etc/mysql/debian.cnf mysql -Bse 'UPDATE user SET password=PASSWORD("$mysql_passwd") WHERE User="root";flush privileges;'
When running the command from the script without the variable (with just the password directly in it) it works:
mysql --defaults-file=/etc/mysql/debian.cnf mysql -Bse 'UPDATE user SET password=PASSWORD("password") WHERE User="root";flush privileges;'
tried things like:
PASSWORD("$mysql_passwd")
PASSWORD("${mysql_passwd}")
PASSWORD('$mysql_passwd')
No error message, the root password just doesn't change.
Thank you for reading.