Skip to content

Instantly share code, notes, and snippets.

@jaronson
Last active December 28, 2015 03:29
Show Gist options
  • Save jaronson/7435965 to your computer and use it in GitHub Desktop.
Save jaronson/7435965 to your computer and use it in GitHub Desktop.
#!/bin/bash
export MYSQL_PASS=
function mysql_search_schema_usage(){
cat << EOF
usage: $0 <terms> [database]
EOF
}
function mysql_search_schema(){
if [[ -z $1 ]]
then
mysql_search_schema_usage
else
cmd="mysql -uroot -p$MYSQL_PASS -e"
query="SELECT table_schema, table_name, column_name FROM information_schema.columns WHERE (table_name LIKE '%$1' OR column_name LIKE '%$1')"
if [[ -n $2 ]]
then
query="$query AND table_schema = $2"
fi
eval "$cmd \"$query\""
fi
}
alias searchschema=mysql_search_schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment