Last active
January 1, 2016 05:29
-
-
Save thejsj/8099370 to your computer and use it in GitHub Desktop.
Another iteration into a script that creates a database and user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
params=" -uroot -p" | |
echo ' - - - - - - - ' | |
echo 'DB Name : '$1 | |
echo 'Password: '$2 | |
# Create Database | |
echo ' - - - - - - - ' | |
echo 'CREATE DATABASE IF NOT EXISTS $1;' | |
# Grant Options (Creates User Automatically) | |
echo ' - - - - - - - ' | |
echo "GRANT ALL PRIVILEGES ON $1.* | |
TO '$1'@'%' IDENTIFIED BY '$2' | |
WITH GRANT OPTION;" | |
read -p "Do you wish to install this program? [Y/N] : " yn | |
if [ $yn = "y" -o $yn = "Y" ]; then | |
# Create Database | |
mysql $params <<DELIMITER | |
CREATE DATABASE IF NOT EXISTS $1; | |
DELIMITER | |
# Grant Options (Creates User Automatically) | |
# http://stackoverflow.com/questions/4528393/mysql-create-user-only-when-the-user-doesnt-exist | |
mysql $params <<DELIMITER | |
GRANT ALL PRIVILEGES ON $1.* | |
TO '$1'@'%' IDENTIFIED BY '$2' | |
WITH GRANT OPTION; | |
DELIMITER | |
mysql $params <<DELIMITER | |
GRANT ALL PRIVILEGES ON $1.* | |
TO '$1'@'localhost' IDENTIFIED BY '$2' | |
WITH GRANT OPTION; | |
DELIMITER | |
mysql $params <<DELIMITER | |
GRANT ALL PRIVILEGES ON $1.* | |
TO '$1'@'127.0.0.1' IDENTIFIED BY '$2' | |
WITH GRANT OPTION; | |
DELIMITER | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment