#!/bin/bash case "$1" in -t|--tables) TABLES=$(echo "$2" | tr -d ' ' | tr ',' '\n') shift 2 ;; esac DATABASE=$1 if [ -z "$DATABASE" ] then echo "usage: dump_stats [-tables table1,table2...] DATABASE [ ...mysql_args]" >&2 exit 1 fi shift #for x in `mysql $* -NABe "show tables from $DATABASE"` ; do # mysql $* -e "ANALYZE TABLE $DATABASE.$x" >/dev/null 2>&1 #done MYSQL_STATS=`mktemp` mysql $* -ABe "select * from information_schema.statistics where table_schema = '$DATABASE'" > $MYSQL_STATS if ! [ -s $MYSQL_STATS ] then echo "no such database: $DATABASE" >&2 exit 1 fi if [ "$TABLES" ] then filtered=`mktemp` head -n 1 $MYSQL_STATS >> $filtered for t in $TABLES do awk -v tbl=$t '{ if ($3 == tbl) print $0 }' $MYSQL_STATS >> $filtered done MYSQL_STATS=$filtered fi bundle exec ruby -e "require 'shiba/index'; puts Shiba::Index.parse('$MYSQL_STATS').to_yaml"