Last active
April 11, 2017 23:45
-
-
Save selvavalluvan/3b7d1958a28811d27e59dceeb0f85dea to your computer and use it in GitHub Desktop.
Mysql setup script
This file contains hidden or 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
| #!/usr/bin/env bash | |
| MYSQL=`which mysql` | |
| DB_NAME="product" | |
| DB_USER="quietly_product" | |
| DB_PASSWORD=$(awk '$1 ~ /DB_PASSWORD/ {print $1 }' ./.env | sed "s/^DB_PASSWORD=\(.*\)$/\1/") | |
| DB_ADMIN_USER="quietly_admin" | |
| DB_ADMIN_PASSWORD=$(awk '$1 ~ /DB_ADMIN_PASSWORD/ {print $1 }' ./.env | sed "s/^DB_ADMIN_PASSWORD=\(.*\)$/\1/") | |
| Q1_0="CREATE USER IF NOT EXISTS $DB_USER@localhost IDENTIFIED BY '$DB_PASSWORD';" | |
| Q1_1="CREATE USER IF NOT EXISTS $DB_ADMIN_USER@localhost IDENTIFIED BY '$DB_ADMIN_PASSWORD';" | |
| Q2="CREATE DATABASE IF NOT EXISTS $DB_NAME;" | |
| Q3_0="GRANT USAGE ON *.* TO $DB_USER@localhost IDENTIFIED BY '$DB_PASSWORD';" | |
| Q3_1="GRANT USAGE ON *.* TO $DB_ADMIN_USER@localhost IDENTIFIED BY '$DB_ADMIN_PASSWORD';" | |
| Q4_0="GRANT SELECT, INSERT, UPDATE, DELETE ON $DB_NAME.* TO $DB_USER@localhost;" | |
| Q4_1="GRANT ALL PRIVILEGES ON $DB_NAME.* TO $DB_ADMIN_USER@localhost;" | |
| Q5="FLUSH PRIVILEGES;" | |
| SQL="${Q1_0}${Q1_1}${Q2}${Q3_0}${Q3_1}${Q4_0}${Q4_1}" | |
| echo "Type your mysql root password" | |
| $MYSQL -uroot -p -e "$SQL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment