shell 脚本连接mysql数据库查询database中表的数量和表名
#!/bin/bash MYSQLHOST="127.0.0.1" MYSQLUSER="root" MYSQLPWD="root" MYSQLPORT="3306" MYSQLDB="test" echo "health tables total:" > mysqlCount.txt; mysql -h$MYSQLHOST -u$MYSQLUSER -p$MYSQLPWD -P$MYSQLPORT -D$MYSQLDB -Bse "select count(*) from information_schema.tables where table_schema =\"$MYSQLDB\";">>mysqlCountLocal.txt; mysql -h$MYSQLHOST -u$MYSQLUSER -p$MYSQLPWD -P$MYSQLPORT -D$MYSQLDB -Bse "select table_name,table_rows from information_schema.tables where table_schema =\"$MYSQLDB\";" >>mysqlCountLocal.txt
该脚本的作用:
查询该database 中有多少长表,并写入mysqlCountLocal.txt文件
查询该库中每个表的名字和条数,追加到mysqlCountLocal.txt文件中