#!/bin/sh
#
# sh sql/setup_dbuser.sh $DBUSER $DBPASSWD $DBROOT_PWD

DBUSER=$1
DBPASSWD=$2
DBROOT_PWD=$3

# Root Password
#
# If you forgot the password, run /usr/bin/mysqld_safe --skip-grant-tables
# mysql -u root mysql
# mysql> UPDATE user SET Password=PASSWORD('new-password') WHERE User='root';
# mysql> FLUSH PRIVILEGES;
#
#/usr/bin/mysqladmin -u root password '$DBROOT_PWD'
#/usr/bin/mysqladmin -u root -p$DBROOT_PWD password '$DBROOT_PWD'

# Create new user
mysql -u root mysql -p$DBROOT_PWD -e "grant all privileges on *.* to $DBUSER@localhost identified by '$DBPASSWD'"
mysql -u root mysql -p$DBROOT_PWD -e "grant all privileges on *.* to $DBUSER@'%' identified by '$DBPASSWD'"
mysql -u root mysql -p$DBROOT_PWD -e "grant file on *.* to $DBUSER@localhost"
mysql -u root mysql -p$DBROOT_PWD -e "grant file on *.* to $DBUSER@'%'"
mysql -u root -p$DBROOT_PWD -e "flush privileges"


