Skip to content

Instantly share code, notes, and snippets.

@cjnewbs
Created February 18, 2018 21:01
Show Gist options
  • Save cjnewbs/9ef7c7d62416addacf917fba3882cbb5 to your computer and use it in GitHub Desktop.
Save cjnewbs/9ef7c7d62416addacf917fba3882cbb5 to your computer and use it in GitHub Desktop.
Script to simply the creation of new MySQL databases
#!/bin/bash
echo "Please enter the name of the new DB to create:"
read NEW_DB
echo "Please enter the name of the new DB username:"
read NEW_USER
echo "Please enter the name of the new DB password:"
read -s NEW_PASS
echo "Please re-enter the name of the new DB password:"
read -s NEW_PASS_CONFIRM
if [ "$NEW_PASS" == "$NEW_PASS_CONFIRM" ]
then
echo "Creting new DB named $NEW_DB owned by $NEW_USER"
echo "You will need the MySQL root password for this:"
mysql -u root -p -e "CREATE USER '$NEW_USER'@'localhost' IDENTIFIED BY '$NEW_PASS';CREATE DATABASE $NEW_DB;GRANT ALL PRIVILEGES ON $NEW_DB . * TO '$NEW_USER'@'localhost';FLUSH PRIVILEGES;"
if [ $? -eq 0 ]
then
echo "Database sucessfully created!"
fi
else
echo "Passwords do not match please try again"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment