[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [cobalt-users] [RAQ550]Automatic mysql user creation



Found this on the net some time ago.  It sets things up nicely and even
works with phpMyAdmin.

tput clear
echo "*****************************************"
echo "  MySQL Database Creator"
echo -e "*****************************************\n\n"
echo "This script will create a MySQL database."
echo "The DATABASE will be named after the USERNAME."
echo -e "Please supply the USERNAME and PASSWORD for the new database.\n"

echo -n "Username: "
read username

echo -n "Password: "
read password

echo -e "\nThe following database will be created:"
echo "DATABASE: $username"
echo "USERNAME: $username"
echo "PASSWORD: $password"

echo -e "\n\nNow i need the root password to enter MySQL"
echo -n "Password to enter MySQL: "
read rootpassword

mysql -u root -p$rootpassword -e"INSERT INTO user (host,user,password)
VALUES ('localhost','$username',Password('$password'));" mysql
mysql -u root -p$rootpassword -e"INSERT INTO db
(host,db,user,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Dr
op_priv,Alter_priv,Index_priv) VALUES
('localhost','$username','$username','Y','Y','Y','Y','Y','Y','Y','Y');"
mysql
mysqladmin -u root -p$rootpassword create $username
mysqladmin -u root -p$rootpassword reload

echo -e "\n\nIf no error appeared, the database is setup correctly."