Created
November 16, 2011 17:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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