Bash script: report largest InnoDB files
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的更多相关文章
- 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 ...
- Linux: bash script
content [toc] bash scripts equivalent bash command to rename a bash variable/command alias fire='fir ...
- Run bash script as daemon
linux - Run bash script as daemon - Stack Overflow https://stackoverflow.com/questions/19233529/run- ...
- Linux bash script regex auto replace
Linux bash script regex auto replace 自动替换 /assets/css/0.styles.96df394b.css => ./assets/css/0.sty ...
- Linux Bash Script conditions
Linux Bash Script conditions shell 编程之条件判断 条件判断式语句.单分支 if 语句.双分支 if 语句.多分支 if 语句.case 语句 refs http:/ ...
- Linux Bash Script loop
Linux Bash Script loop shell 编程之流程控制 for 循环.while 循环和 until 循环 for var in item1 item2 ... itemN do c ...
- 【学习笔记】linux bash script
1. sed sed 是一种流编辑器,它是文本处理中非常常用的工具,能够完美的配合正则表达式使用,功能非常强大. mkdir playground touch test.txt echo " ...
- [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. ...
- 高级Bash Scripting系列笔记--01之“什么情况不适用Bash Script”
1. 占用资源的任务,尤其那些影响速度的工作 比如排序,哈希,递归等等. 2. 大量使用数学运算 尤其是浮点运算,比如任意精度的计算或者复数计算等等,这类使用C++会好很多. 3. 跨平台的(适用 ...
随机推荐
- 学习python第一天 pycharm设置
print(“hello,world”) pycharm设置 1. 选择python 解析器,目的是确定pycharm 的运行环境. 方法: File-->Settings-->Proje ...
- python七类之字典详解
一.字典 一.关键字:dict 1.字典是唯一的键值对数据,其表现形式: dic = {键:值},字典里的键必须保证是唯一的 2.键必须是不可变的数据类型: a.故列表是不能当键的 b.所 ...
- 最短路径问题 3.Bellman-Ford算法
简要:Bellman-Ford算法计算的仍然是从一个点到其他所有点的最短路径算法,其时间复杂度是O(NE),N表示点数,E表示边数,不难看出,当一个图稍微稠密一点,边的数量会超过点数那么实际上效率是低 ...
- NO-ZERO(空格补全)
The NO-ZERO command follows the DATA statement REPORT Z_Test123_01. DATA: W_NUR(10) TYPE N. MOVE 50 ...
- Create Fiori List App Report with ABAP CDS view – PART 2
In the Part 1 blog, we have discussed below topics CDS annotations for Fiori List Report. How to cre ...
- xampps 不能配置非安装目录虚拟主机解决方案
今天将前几天安装好的xampps配置下,准备开始php开发之旅,在我信心满满的将工作目录定在非安装目录上(安装目录在:D:\Program Files\xampps\apache\htdocs 我将 ...
- atlas+mysql主主集群实现读写分离
atlas+mysql主主集群实现读写分离 前言: 目前线上系统数据库采用的是主主架构.其中一台主仅在故障时切换使用,(仅单台服务器对外提供服务,当一台出现问题,切换至另一台).该结构很难支撑较大并 ...
- mysql用命令创建用户创建数据库设置权限
1.create database bbs; //创建数据库 2.create user bbs IDENTIFIED by 'bbs'; //创建用户bbs和登录密码bbs 3.grant AL ...
- python eval()函数的妙用和滥用
eval()函数十分强大,官方demo解释为:将字符串str当成有效的表达式来求值并返回计算结果: >>> s='8*8' >>> eval(s) 64 >& ...
- Ubuntu server中 samba的安装和简单配置
samba是Linux系统上的一种文件共享协议,可以实现Windows系统访问Linux系统上的共享资源,现在介绍一下如何在Ubuntu 14.04上安装和配置samba 工具/原料 Ubuntu ...