Created
February 6, 2012 02:58
-
-
Save fk2000/1749264 to your computer and use it in GitHub Desktop.
MySQLのテーブル定義をHTMLに出力するシェル
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/sh | |
## base config | |
MYSQL_BIN=mysql | |
MYSQL_USER=user | |
MYSQL_PASSWD=password | |
MYSQL_HOST=localhost | |
## 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 -h $MYSQL_HOST $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