#统计指定架构的所有表的数据和索引大小情况
#tablesize. Sh
#!/bin/sh
#[email protected]
If ["$#"-GT 2];then
echo "**********************************"
echo "Too many input parameters"
echo "**********************************"
echo "USAGE01: $ schema_name table_name"
echo "EG01: $ wind T1"
echo "USAGE02: $ schema_name"
echo "EG02: $ Wind"
Exit 1;
Fi
Source/usr/local/mysql/scripts/mysql_env.ini
Logfiledate=tmp. ' Date +%y%m%d%h%m%s '. txt
Schema_name=$1
Table_name=$2
If ["$#"-eq 2];then
sql_cmd= "Select Table_schema, Table_name,table_rows,
round (SUM (data_ Length+index_length)/1024/1024) as TOTAL_MB,
round (sum (data_length)/1024/1024) as DATA_MB,
round (SUM (index_length)/1024/1024) as INDEX_MB
from information_schema.tables where table_type= ' BASE table ' and Table_schema= ' ${schema_name} '
and table_name= ' ${table_name} '
group by Table_schema, Table_ Name,table_rows; "
Else
sql_cmd= "Select Table_schema, Table_name,table_rows,
round (SUM (data_length+index_ Length)/1024/1024) as TOTAL_MB,
round (sum (data_length)/1024/1024) as DATA_MB,
round (SUM (index_ Length)/1024/1024) as INDEX_MB
from information_schema.tables where table_type= ' BASE table ' and Table_ Schema= ' ${schema_name} '
group by Table_schema, table_name,table_rows; "
Fi
Schema_judege= "SELECT * from Information_schema.schemata where schema_name= ' ${schema_name} ';"
Mysql-h${mysql_host}-u${mysql_user}-p${mysql_pass}-E "${schema_judege}" >${logfiledate}
If [-E "${logfiledate}"-A!-S "${logfiledate}"];then
echo "You input ${schema_name} not Exits,pleae check your databases"
RM-RF ${logfiledate}
Else
echo "The result is:"
Mysql-h${mysql_host}-u${mysql_user}-p${mysql_pass}-E "${sql_cmd}"
RM-RF ${logfiledate}
Fi