Skip to content

Instantly share code, notes, and snippets.

@timf
Forked from jaronson/mysql-search-schema.sh
Created December 6, 2013 20:01
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 timf/7831204 to your computer and use it in GitHub Desktop.
Save timf/7831204 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