zoukankan      html  css  js  c++  java
  • 实战:mysql统计指定架构的全部表的数据和索引大小情况-v2

    PS:第一个版本号里未做输入的schema_name和table_name推断,改动了一下!再次share!

    #统计指定架构的全部表的数据和索引大小情况
    #tablesize.sh
    #!/bin/sh
    #ocpyang@126.com

    if [ "$#" -gt 2 -o "$#" -lt 1 ];then
    echo "**********************************"
    echo "too many input parameters"
    echo "**********************************"
    echo "USAGE01: $0 schema_name table_name"
    echo "eg01: $0 wind t1"
    echo "USAGE02: $0 schema_name "
    echo "eg02: $0 wind "
    exit 1;
    fi


    #set mysql evn
    MYSQL_USER=system  #mysql的username
    MYSQL_PASS='password'  #mysql的登录用户密码
    MYSQL_HOST=192.168.2.188


    judegedate_01="judegedate01.`date +%Y%m%d%H%M%S`.txt"

    judegedate_02="judegedate02.`date +%Y%m%d%H%M%S`.txt"


    SCHEMA_NAME=$1
    TABLE_NAME=$2

    #judege

    SCHEMA_JUDEGE="select schema_name from information_schema.schemata where schema_name='${SCHEMA_NAME}';"
    mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS} -e"${SCHEMA_JUDEGE}" >${judegedate_01}


    TABLE_JUDEGE="select table_name from information_schema.tables where table_name='${TABLE_NAME}';"
    mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS} -e"${TABLE_JUDEGE}" >${judegedate_02}

    if [ "$#" -eq 2 ];then
     if [ ! -s "${judegedate_01}" ];then
     echo "****************************************************************************"
     echo "you input schema_name ${SCHEMA_NAME} not exits,pleae check your databases"
     echo "*****************************************************************************"
     rm -rf ${judegedate_01}
     rm -rf ${judegedate_02}
     exit 0
     fi
     if [ ! -s "${judegedate_02}" ];then
     echo "*****************************************************************************"
     echo "you input table_name ${TABLE_NAME} not exits,pleae check your databases"
     echo "*****************************************************************************"
     rm -rf ${judegedate_01}
     rm -rf ${judegedate_02}
     exit 0
     fi

     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;"
     echo "the result is :"
     mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS} -e"${SQL_CMD}"
     rm -rf ${judegedate_01}
     rm -rf ${judegedate_02}
    else 
     if [ ! -s "${judegedate_01}" ];then
     echo "*****************************************************************************"
     echo "you input schema_name ${SCHEMA_NAME} not exits,pleae check your databases"
     echo "*****************************************************************************"
     rm -rf ${judegedate_01}
     rm -rf ${judegedate_02}
     exit 0
     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;"
     echo "the result is :"
     mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS} -e"${SQL_CMD}"
     rm -rf ${judegedate_01}
     rm -rf ${judegedate_02}
     fi
    fi

  • 相关阅读:
    SQL2005自动备份,定期删除的维护计划及自动定期清除日志
    asp.net(C#)生成Code39条形码 条码枪可以扫描出
    Oracle中自定义函数 无参数 输入参数 输出参数等各种用法
    SQL Server2005 实现两台服务器上的数据库同步
    C#后台给某网址传递参数,并接收返回值
    LINUX 11G RAC ASM磁盘组在线增加磁盘扩容 .
    使用SQL*PLUS构建完美excel或html输出
    Oracle RAC + Data Guard 环境搭建 .
    ORA15097: cannot SHUTDOWN ASM instance with connected client 和 ORA01031: insufficient privileges 处理方法
    AIX性能监控topas命令的详细解析
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5410055.html
Copyright © 2011-2022 走看看