ysql 统计表条数脚本


#!/bin/sh
DATABASE="gm"
DB_HOST="localhost"
DB_USER="root"
DB_PASSWORD="syqodbzv"

show_all_tables() {
    echo "use ${DATABASE}; show tables;" | mysql -u${DB_USER} -p${DB_PASSWORD} -h ${DB_HOST}
}

count_tables() {
    for table in `show_all_tables | grep -v Tables`;
    do
        echo "use ${DATABASE}; select '${table}', count(1) from ${table};" | mysql -u${DB_USER} -p${DB_PASSWORD} -h ${DB_HOST} |grep -v count>> count_tables.sql
    done
}

count_tables