首页 > 数据库技术 > 详细

shell 脚本获取MySQL数据库中所有表记录总数

时间:2019-02-19 11:35:32      阅读:368      评论:0      收藏:0      [点我收藏+]
近期遇到一个需求,Mysql数据库中需要统计所有表的记录数据:
查了下资料可以调取information_schema数据表中数据获取所有表记录数据,但是查询出来的数据,发现和手动统计的记录数据不一致,information_schema查询出来的数据部分不准确【原因应该是部分表数据没有自动同步】。折腾了下,于是还是自己手动写个脚本,分享下也做下次备用。
程序结构:
#!/bin/bash

Author:Jerry

tb_name=mysql -u账号 -p密码 -h192.168.x.x -P端口 -e "select table_name from information_schema.tables where table_schema=‘数据库名‘"|awk ‘NR>1{print $1}‘
for name in $tb_name ;
do
tbl_count=mysql -u账号 -p密码 -h192.168.x.x -P端口 -e "select count (*) as times from cwsys.$name;"| tail -1
echo "$name=$tbl_count" >>/home/xxx/xxx.log
done

技术分享图片
执行脚本:
技术分享图片
查看生成的统计记录:
技术分享图片
查看统计数据:
技术分享图片

shell 脚本获取MySQL数据库中所有表记录总数

原文:http://blog.51cto.com/jdonghong/2351689

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!