Skip to content

Instantly share code, notes, and snippets.

@innesm4
Created May 24, 2014 14:32
Show Gist options
  • Select an option

  • Save innesm4/80e97d5e842e131ee38d to your computer and use it in GitHub Desktop.

Select an option

Save innesm4/80e97d5e842e131ee38d to your computer and use it in GitHub Desktop.
#!/bin/bash
echo -n "Enter the MySQL root password: "
read -s rootpw
echo -n "Enter database name: "
read dbname
echo -n "Enter database username: "
read dbuser
echo -n "Enter database user password: "
read dbpw
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"
exit 1
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment