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. hive表格取差集

    hive 求两个集合的差集 业务场景是这样的,这里由两个hive表格A和B A的形式大概是这样的:uid B的形式大概是这样的:uid 我想要得到存在A中但是不存在B中的uid 具体代码如下 sele ...

  2. python 用装饰器写登录

    # 1.编写装饰器,为多个函数加上认证的功能(用户的账号密码来源于文件), # 要求登录成功一次,后续的函数都无需再输入用户名和密码 # FLAG = False # def login(func): ...

  3. octave简易操作

    语言以分号;结尾if for while等语句后用,来承接关系if ,elseif ,else ,end;for i=1:10,end;while a>3 ,end;   while true, ...

  4. 0301001_Lesson1&2

    Lesson 1 Excuse me! 对不起! Listen to the tape then answer this question.Whose handbag is it?听录音,然后回答问题 ...

  5. Java常考面试题

    Java常考面试题 1. 什么是Java虚拟机?为什么Java被称作是“平台无关的编程语言”? 答:Java虚拟机是一个可以执行Java字节码的虚拟机进程.Java源文件被编译成能被Java虚拟机执行 ...

  6. Jquery操作select选项集合!

    Query获取Select选择的Text和Value: 1. $("#select_id").change(function(){//code...}); //为Select添加事 ...

  7. PostgreSQL字段名和表名大小写的问题

    创建表的时候,表名和字段名必须全小写,然后查询的时候不管全大写或全小写,或是Camel模式都不会报错.只要名称中有大写字母,或者全大写,查询时就必须保证大小写正确并用双引号包起来,否则就会报“XXX不 ...

  8. SGU刷题之路,开始了

    0. 关于SGU的简介 SGU的网址是:acm.sgu.ru 向不了解的同学介绍一下SGU这个题库: 1. 题目难度很高,题目大多很经典. 2. 其数据范围很小,时间和空间要求也都很小,同时很精确.甚 ...

  9. OpenCV入门:(七:OpenCV取随机数以及显示文字)

    1.随机颜色 OpenCV中自带了取随机数的方法,使用步骤: RNG rng( 0xFFFFFFFF ); 随机数 = rng.uniform( 下限,上限 ); 2.显示文字 , , bool bo ...

  10. TW实习日记:第15天

    今天又是修修补补的一天,不过最开心的是因为项目比较特殊,有自己的后端服务器,有一些接口相关的bug可以让我直接写Java代码,终于可以碰一碰Java了哈哈.有好几个bug都是之前的人粗心设置了多余或者 ...