有時候需要給不太懂mysql的用戶提供一種快速查看mysql表信息的腳本,下面的shell整好符合要求
#!/bin/bash
DB_USER="DB_USER"
DB_PASS="DB_PASS"
DB_NAME="DB_NAME"
DATE=`date +%F-%H-%M-%S`
/usr/bin/mysql -u$DB_USER -p$DB_PASS -e "select count(1) table num from information_schema.tables where table_schema='$DB_NAME'" > db_$DATE.info
/usr/bin/mysql -u$DB_USER -p$DB_PASS -e "select TABLE_NAME,TABLE_COMMENT,TABLE_ROWS from information_schema.tables where table_schema='$DB_NAME' \t" >> db_$DATE.info