Created
February 8, 2016 10:34
-
-
Save radmen/1a57cfba0e534f2fb03d to your computer and use it in GitHub Desktop.
Include `.env` file and connect to MySQL
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
# connect to mysql using .env file | |
env-mysql () | |
{ | |
yellow=$(tput -Txterm setaf 3) | |
lt_blue=$(tput -Txterm setaf 6) | |
reset=$(tput -Txterm sgr0) | |
if [ -f .env ]; then | |
. .env | |
fi | |
if [ -z "$DB_DATABASE" ]; then | |
echo "Seems like .env file was not loaded" | |
return 1 | |
fi | |
DB_HOST=${DB_HOST:-localhost} | |
echo "Connecting to $yellow$DB_DATABASE$reset on host $lt_blue$DB_HOST$reset" | |
echo "" | |
mysql -h$DB_HOST -u$DB_USERNAME -p$DB_PASSWORD $DB_DATABASE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment