Skip to content

Instantly share code, notes, and snippets.

@radmen
Created February 8, 2016 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radmen/1a57cfba0e534f2fb03d to your computer and use it in GitHub Desktop.
Save radmen/1a57cfba0e534f2fb03d to your computer and use it in GitHub Desktop.
Include `.env` file and connect to MySQL
# 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