shell 腳本獲取MySQL數據庫中所有表記錄總數
阿新 • • 發佈:2019-02-19
mes ec2 vpd ext 數據不一致 proc info 自己 一個 近期遇到一個需求,Mysql數據庫中需要統計所有表的記錄數據:
查了下資料可以調取information_schema數據表中數據獲取所有表記錄數據,但是查詢出來的數據,發現和手動統計的記錄數據不一致,information_schema查詢出來的數據部分不準確【原因應該是部分表數據沒有自動同步】。折騰了下,於是還是自己手動寫個腳本,分享下也做下次備用。
程序結構:
#!/bin/bash
for name in $tb_name ;
do
tbl_count=
echo "$name=$tbl_count" >>/home/xxx/xxx.log
done
查了下資料可以調取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數據庫中所有表記錄總數