Create user with assigned DB script

#!/bin/bash
echo-n "Enter the MySQL root password: "
read-s rootpw
echo-n "Enter database name: "
readdbname
echo-n "Enter database username: "
readdbuser
echo-n "Enter database user password: "
readdbpw
db="create database $dbname;GRANT ALL PRIVILEGES ON $dbname.* TO $dbuser@localhost IDENTIFIED BY '$dbpw';FLUSH PRIVILEGES;"
mysql -u root -p$rootpw -e "$db"
if[ $? != "0"]; then
 echo"[Error]: Database creation failed"
 exit1
else
 echo"------------------------------------------"
 echo" Database has been created successfully "
 echo"------------------------------------------"
 echo" DB Info: "
 echo""
 echo" DB Name: $dbname"
 echo" DB User: $dbuser"
 echo" DB Pass: $dbpw"
 echo""
 echo"------------------------------------------"
fi
Jan D.
Jan D.

"The only real security that a man will have in this world is a reserve of knowledge, experience, and ability."

Articles: 673

Leave a Reply

Vaše e-mailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *