Skip to content

Instantly share code, notes, and snippets.

@JoolsF
Created August 13, 2018 10:29
Show Gist options
  • Select an option

  • Save JoolsF/59623d4bfcbe8de8951936c80a8316c6 to your computer and use it in GitHub Desktop.

Select an option

Save JoolsF/59623d4bfcbe8de8951936c80a8316c6 to your computer and use it in GitHub Desktop.
db query shell script
#!/usr/bin/env bash
DB_USER="???"
DB_PASS="???"
DB_HOST="???"
if [ ! "$DB_USER" ] || [ ! "$DB_PASS" ] || [ ! "$DB_HOST" ]; then
echo "You need to set DB_USER, DB_PASS and DB_HOST environmental variables."
exit 1
fi
# escape new lines and backticks
mysql -u${DB_USER} \
-p${DB_PASS} \
-h${DB_HOST} \
my_db_name -e "SELECT * \
FROM \`foo\`.\`bar\` fb";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment