I have a shell script which has the following content:
#!/bin/sh
mysql -uqgk_user -ppw12345 -e "create database qgk; GRANT ALL PRIVILEGES ON qgk.* TO qgk_user@localhost IDENTIFIED BY 'pw12345' WITH GRANT OPTION;"
I receive this error if I run the shell script:
manager@xagate:/var/www/.../public_html/...$ sh database_setup.sh
ERROR 1045 (28000): Access denied for user 'qgk_user'@'localhost' (using password: YES)
I don't understand why this issue is occurring. Anyone who posts a working solution for this issue can include their Ripple address within their answer to be rewarded XRP for their assistance with this issue.
This is how I solved this issue:
manager@xagate:/var/www$ cat mysql_setup.sh
#!/bin/bash
EXPECTED_ARGS=3
E_BADARGS=65
MYSQL=`which mysql`
Q1="CREATE DATABASE IF NOT EXISTS $1;"
Q2="GRANT USAGE ON *.* TO $2@localhost IDENTIFIED BY '$3';"
Q3="GRANT ALL PRIVILEGES ON $1.* TO $2@localhost;"
Q4="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}${Q4}"
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: $0 qgk qgk_user PASSWORD"
exit $E_BADARGS
fi
$MYSQL -uroot -p -e "$SQL"
I then had to login to Webmin an navigate to Servers > MySQL Database Server > User Permissions > root@localhost > reassigned the password.
When prompted for a password at the execution time of the mysql_setup.sh script and inputting the root@localhost user's password, the database was created along with the qgk_user and chosen password.
Thank you for your assistance, sir :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.