Skip to content

Instantly share code, notes, and snippets.

@ashfame
Created November 16, 2011 17:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashfame/1370753 to your computer and use it in GitHub Desktop.
Save ashfame/1370753 to your computer and use it in GitHub Desktop.
Bash script to generate a html file describing all tables in a database
#!/bin/bash
#Change your db username, password & database name
if [ -f ~/Desktop/db_schema.html ]; then
rm ~/Desktop/db_schema.html
fi
for i in `mysql -B -N -uroot -proot dbname -e 'show tables;'`; do
echo "<a href='#$i'>$i</a><br />" >> /tmp/$$.nav.html
echo "<a name='$i'></a>" >> /tmp/$$.tables.html
echo "<h2>$i</h2>" >> /tmp/$$.tables.html
mysql --html --column-names -uroot -proot dbname -e "desc $i;" >> /tmp/$$.tables.html
echo -n >> /tmp/$$.tables.html
done;
cat /tmp/$$.nav.html /tmp/$$.tables.html > ~/Desktop/db_schema.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment