sh 获取数据库统计信息

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 获取数据库统计信息相关的知识,希望对你有一定的参考价值。

#!/bin/bash

user_dev="s12876"
pass_dev="RxbJb8EhRd6m2Zk"
host_dev="staging-12090"

declare -A bases_dev
bases_dev[eurailcommerce]="eurailcommercedev"
bases_dev[germanrailpassescommerce]="eurailcomdb46203"
bases_dev[interrailcommerce]="eurailcomdb46138"
bases_dev[jobs]="eurailcomdb52339"


user_stage="s12875"
pass_stage="xDzzcdghG5ZcFHd"
host_stage="staging-12090"

declare -A bases_stage
bases_stage[eurailcommerce]="eurailcommercestage1"
bases_stage[germanrailpassescommerce]="eurailcomdb46205"
bases_stage[interrailcommerce]="eurailcomdb46140"
bases_stage[jobs]="eurailcomdb52341"


echo "DEV"
echo ""

echo "Legend:"
for key in "${!bases_dev[@]}"; do echo "$key => ${bases_dev[$key]}"; done
echo ""

echo "Total DB sizes"
 mysql -h${host_dev} -u${user_dev} -p${pass_dev} -e "SELECT SQL_NO_CACHE IFNULL(table_schema,'Total') 'Database' , Round(Sum(data_length) / 1024 / 1024, 1) 'Data Size in MB',Round(Sum(index_length) / 1024 / 1024, 1) 'Index Size in MB', Round(SUM(data_length + index_length) / 1024 / 1024,1) 'Total in MB'  FROM   information_schema.tables GROUP  BY table_schema with ROLLUP;"
echo ""

for key in "${!bases_dev[@]}"; do
  echo "TOP 30 tables for $key :: ${bases_dev[$key]}"
  mysql -h${host_dev} -u${user_dev} -p${pass_dev} -e "SELECT SQL_NO_CACHE CONCAT(table_schema, '.', table_name) as Table_name, CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows, CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA, CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx, CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size, ROUND(index_length / data_length, 2) idxfrac FROM information_schema.TABLES WHERE table_schema = '${bases_dev[$key]}'  ORDER BY data_length + index_length DESC LIMIT 30;"
echo ""
done

echo ""
echo "--------------------------------------------------------------"
echo ""

echo "STAGE"
echo ""

echo "Legend:"
for key in "${!bases_stage[@]}"; do echo "$key => ${bases_stage[$key]}"; done
echo ""

echo "Total DB sizes"
 mysql -h${host_stage} -u${user_stage} -p${pass_stage} -e "SELECT SQL_NO_CACHE IFNULL(table_schema,'Total') 'Database' , Round(Sum(data_length) / 1024 / 1024, 1) 'Data Size in MB',Round(Sum(index_length) / 1024 / 1024, 1) 'Index Size in MB', Round(SUM(data_length + index_length) / 1024 / 1024,1) 'Total in MB'  FROM   information_schema.tables GROUP  BY table_schema with ROLLUP;"
echo ""

for key in "${!bases_stage[@]}"; do
  echo "TOP 30 tables for $key :: ${bases_stage[$key]}"
  mysql -h${host_stage} -u${user_stage} -p${pass_stage} -e "SELECT SQL_NO_CACHE CONCAT(table_schema, '.', table_name) as Table_name, CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows, CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA, CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx, CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size, ROUND(index_length / data_length, 2) idxfrac FROM information_schema.TABLES WHERE table_schema = '${bases_stage[$key]}'  ORDER BY data_length + index_length DESC LIMIT 30;"
echo""
done


echo ""
echo "--------------------------------------------------------------"
echo ""

echo "Disk Usage on Server"
echo ""
df -Th

以上是关于sh 获取数据库统计信息的主要内容,如果未能解决你的问题,请参考以下文章

sh 获取所有装配统计信息

sh 从Linux收集统计信息

sh 在docker 1.5中由docker-compose启动运行容器的统计信息

Python获取阿拉丁统计信息

Python获取阿拉丁统计信息

WebRTC Native M96数据统计-- 使用PeerConnection::GetStats获取WebRTC实时统计信息