The following script will report the largest InnoDB tables under the data directory: schema, table & length in bytes. The tables could be non-partitioned, in which case this is simply the size of the corresponding .ibd file, or they can be partitioned, in which case the reported size is the sum of all partition files. It is assumed tables reside in their own tablespace files, i.e. created with innodb_file_per_table=1.

 (
mysql_datadir=$(grep datadir /etc/my.cnf | cut -d "=" -f )
cd $mysql_datadir
for frm_file in $(find . -name "*.frm")
do
tbl_file=${frm_file//.frm/.ibd}
table_schema=$(echo $frm_file | cut -d "/" -f )
table_name=$(echo $frm_file | cut -d "/" -f | cut -d "." -f )
if [ -f $tbl_file ]
then
# unpartitioned table
file_size=$(du -cb $tbl_file > /dev/null | tail -n )
else
# attempt partitioned innodb table
tbl_file_partitioned=${frm_file//.frm/#*.ibd}
file_size=$(du -cb $tbl_file_partitioned > /dev/null | tail -n )
fi
file_size=${file_size//total/}
# Replace the below with whatever action you want to take,
# for example, push the values into graphite.
echo $file_size $table_schema $table_name
done
) | sort -k -nr | head -n

We use this to push table statistics to our graphite service; we keep an eye on table growth (we actually do not limit to top 20 but just monitor them all). File size does not report the real table data size (this can be smaller due to tablespace fragmentation). It does give the correct information if you're concerned about disk space. For table data we also monitor SHOW TABLE STATUS /INFORMATION_SCHEMA.TABLES, themselves being inaccurate. Gotta go by something.

参考:

http://code.openark.org/blog/mysql/bash-script-report-largest-innodb-files

Bash script: report largest InnoDB files的更多相关文章

  1. Bash+R: howto pass parameters from bash script to R(转)

    From original post @ http://analyticsblog.mecglobal.it/analytics-tools/bashr/ In the world of data a ...

  2. Linux: bash script

    content [toc] bash scripts equivalent bash command to rename a bash variable/command alias fire='fir ...

  3. Run bash script as daemon

    linux - Run bash script as daemon - Stack Overflow https://stackoverflow.com/questions/19233529/run- ...

  4. Linux bash script regex auto replace

    Linux bash script regex auto replace 自动替换 /assets/css/0.styles.96df394b.css => ./assets/css/0.sty ...

  5. Linux Bash Script conditions

    Linux Bash Script conditions shell 编程之条件判断 条件判断式语句.单分支 if 语句.双分支 if 语句.多分支 if 语句.case 语句 refs http:/ ...

  6. Linux Bash Script loop

    Linux Bash Script loop shell 编程之流程控制 for 循环.while 循环和 until 循环 for var in item1 item2 ... itemN do c ...

  7. 【学习笔记】linux bash script

    1. sed sed 是一种流编辑器,它是文本处理中非常常用的工具,能够完美的配合正则表达式使用,功能非常强大. mkdir playground touch test.txt echo " ...

  8. [NPM] Create a bash script to replace a complex npm script

    In this lesson we will look at pulling out complex npm scripts into their own external bash scripts. ...

  9. 高级Bash Scripting系列笔记--01之“什么情况不适用Bash Script”

      1. 占用资源的任务,尤其那些影响速度的工作 比如排序,哈希,递归等等. 2. 大量使用数学运算 尤其是浮点运算,比如任意精度的计算或者复数计算等等,这类使用C++会好很多. 3. 跨平台的(适用 ...

随机推荐

  1. Win10正式版激活

    参考:https://jingyan.baidu.com/article/47a29f2457af76c015239942.html https://jingyan.baidu.com/article ...

  2. 线程基础三 使用C#中的lock关键词

    C#中lock关键字主要是为确保当一个线程使用某些资源时,同时无法其他线程无法使用该资源.下面我们看看下面的小例子. static void Main(string[] args) { var c = ...

  3. python2.7入门---元组

        这次我们来学习下python中的元组.首先,基础认知点是,Python的元组与列表类似,不同之处在于元组的元素不能修改.元组使用小括号,列表使用方括号.元组创建很简单,只需要在括号中添加元素, ...

  4. EAS_Table

    SHR人力 员工表 T_BD_PERSON fbirthday 出生日期 femployeetypeid       员工状态   员工状态  T_HR_BDEMPLOYEETYPE        T ...

  5. C++11中std::bind的使用

    std::bind: Each argument may either be bound to a value or be a placeholder: (1).If bound to a value ...

  6. HTML布局的元素

    header 定义文档或节的页眉 nav 定义导航链接的容器 section 定义文档中的节 article 定义独立的自包含文章 aside 定义内容之外的内容(比如侧栏) footer 定义文档或 ...

  7. LeetCode高频题目(100)汇总-Java实现

    LeetCode高频题目(100)汇总-Java实现       LeetCode高频题目(100)汇总-Java实现 目录 第01-50题 [Leetcode-easy-1] Two Sum [Le ...

  8. 手把手教你写css3通用动画

    之前接了几个微信里的项目,类似电子邀请函,什么分析报告这样的项目, 对css3动画要求十分高,每个页面客户几乎都有天马行空的想法,或者说设计师有这样的想法.众所周知css3里的keyframe写好了就 ...

  9. npx 命令介绍

    这个是在 npmv5.2.0引入的一条命令(查看),引入这个命令的目的是为了提升开发者使用包内提供的命令行工具的体验. 为什么引入这个命令 举个例子,我们开发中要运行 parcel 命令来打包:par ...

  10. 开发react的一些记录

    1.keyboard事件返回的对象SyntheticKeyboardEvent全部是null 解决方法:SyntheticKeyboardEvent的type,which,timeStamp可以得到你 ...