Skip to content

Instantly share code, notes, and snippets.

@DQNEO
Created July 2, 2011 06:05
Show Gist options
  • Save DQNEO/1059781 to your computer and use it in GitHub Desktop.
Save DQNEO/1059781 to your computer and use it in GitHub Desktop.
output MySQL Table Definitions as HTML
#!/bin/sh
## base config
MYSQL_BIN=mysql
MYSQL_USER=user
MYSQL_PASSWD=password
## dbname
if [ "$1" = "" ]; then
echo "no database name"
exit 1;
else
DB_NAME=$1
fi
## table
MYSQL="$MYSQL_BIN -u $MYSQL_USER -p$MYSQL_PASSWD $DB_NAME"
TABLES=`echo "show tables;" | $MYSQL -s`
## print html
echo "<html>"
echo "<head>"
echo "<title>Mysql DB Document : $DB_NAME</title>"
echo "</head>"
echo "<body>"
echo "<h1>Mysql DB Document : $DB_NAME</h1>"
for TABLE_NAME in $TABLES;
do
TABLE_STATUS=(`echo "show table status like '$TABLE_NAME'" | $MYSQL -s`)
echo "<h3>$TABLE_NAME</h3>"
echo "show columns from $TABLE_NAME;" | $MYSQL -H | sed s/\ BORDER=1//
done
echo "</body>"
echo "</html>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment