加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 18:21:04 所属栏目:安全 来源:网络整理
导读:近期遇到一个需求,Mysql数据库中需要统计所有表的记录数据: 查了下资料可以调取information_schema数据表中数据获取所有表记录数据,但是查询出来的数据,发现和手动统计的记录数据不一致,information_schema查询出来的数据部分不准确【原因应该是部分表
近期遇到一个需求,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


执行脚本:


查看生成的统计记录:


查看统计数据:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读