转自(http://www.mysqlperformanceblog.com/2008/03/17/researching-your-mysql-table-sizes/)
Researching your MySQL table sizes
Posted by peter
I posted a simple INFORMATION_SCHEMA query to find largest tables last month and it got a good response. Today I needed little modifications to that query to look into few more aspects of data sizes so here it goes:
Find total number of tables, rows, total data in index size for given MySQL Instance
SELECT count(*) TABLES,
concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES;
+--------+--------+-------+-------+------------+---------+
| TABLES | rows | DATA | idx | total_size | idxfrac |
+--------+--------+-------+-------+------------+---------+
| 35 | 17.38M | 0.32G | 0.00G | 0.32G | 0.00 |
+--------+--------+-------+-------+------------+---------+
Find the same data using some filter
I often use similar queries to find space used by particular table "type" in sharded environment when multiple tables with same structure and similar name exists:
PLAIN TEXT
SQL:
SELECT count(*) TABLES,
concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES
WHERE table_name LIKE "%test%";
+--------+--------+-------+-------+------------+---------+
| TABLES | rows | DATA | idx | total_size | idxfrac |
+--------+--------+-------+-------+------------+---------+
| 1 | 21.85M | 0.41G | 0.00G | 0.41G | 0.00 |
+--------+--------+-------+-------+------------+---------+
1 row in set (0.00 sec)
Find biggest databases
PLAIN TEXT
SQL:
SELECT count(*) TABLES,
table_schema,concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES
GROUP BY table_schema
ORDER BY sum(data_length+index_length) DESC LIMIT 10;
+--------+--------------------+-------+-------+-------+------------+---------+
| TABLES | table_schema | rows | DATA | idx | total_size | idxfrac |
+--------+--------------------+-------+-------+-------+------------+---------+
| 1 | test | 7.31M | 0.14G | 0.00G | 0.14G | 0.00 |
| 17 | mysql | 0.00M | 0.00G | 0.00G | 0.00G | 0.15 |
| 17 | information_schema | NULL | 0.00G | 0.00G | 0.00G | NULL |
+--------+--------------------+-------+-------+-------+------------+---------+
3 rows in set (0.01 sec)
Data Distribution by Storage Engines
You can change this query a bit and get most popular storage engines by number of tables or number of rows instead of data stored.
PLAIN TEXT
SQL:
SELECT engine,
count(*) TABLES,
concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES
GROUP BY engine
ORDER BY sum(data_length+index_length) DESC LIMIT 10;
+--------+--------+--------+-------+-------+------------+---------+
| engine | TABLES | rows | DATA | idx | total_size | idxfrac |
+--------+--------+--------+-------+-------+------------+---------+
| MyISAM | 22 | 26.54M | 0.49G | 0.00G | 0.49G | 0.00 |
| MEMORY | 13 | NULL | 0.00G | 0.00G | 0.00G | NULL |
+--------+--------+--------+-------+-------+------------+---------+
2 rows in set (0.01 sec)
Trivially but handy.
==============================================================
用python写了一个测试数据库的脚本
生成了 26.54M行数据
liuhui@ubuntu:~$ cat test.py
#!/usr/bin/env python
import MySQLdb
import sys
con = MySQLdb.connect(host="localhost",port=3306,user="root",passwd="password",db="test")
cursor = con.cursor()
sql = "insert into test1 (id,name) value(1,'test1')";
for i in range(0,1000000):
if(i%10000 == 0):
print "."
cursor.execute(sql);
分享到:
相关推荐
More and more aspects of our everyday lives are being mediated, augmented, produced and regulated by software-enabled technologies. Software is fundamentally composed of algorithms: sets of defined ...
2021年的科学研究 讲师:理学硕士。 阮安浩 主题名称 学习和使用Selenium Webdriver构建网站的输入功能。 目的 使用软件程序自动输入网站。 这是迈向网站执行自动化测试用例(测试用例)的基本步骤。...
在当今美国教育改革的大潮中,《教学与研究:ELLs的学科素养》一书提出了对英语学习者(ELLs)学科语言能力培养的深入探讨。这本书由Meg Gebhard撰写,为教师、教师教育者和课堂研究者提供了一套全面的理论框架和...
You are an expert in researching and presenting findings in a paper or article form, specializing in a topic of your choice. You have helped many people before me to organize and document material ...
When he's not working, Tim can be found exploring abandoned nuclear power plants and other forgotten landscapes, researching obscure and arcane programming trivia, studying physics, and flying his ...
your company and your clients. We offer research on industries in the US, Canada, Australia, New Zealand, Germany, the UK, Ireland, China and Mexico, as well as industries that are truly global in ...
All of the techniques within this book are explained using fully worked examples that you can immediately apply to your own projects. With each technique the book provides: A practical and useful ...
本文通过康托尔集合(Cantor’s set)对函数对称性进行分析研究。首先,文章从化学领域引入了康托尔思想,指出化学中使用色谱仪测量得到的数据通常是单峰的不对称信号。由此提出问题:是否可以利用康托尔函数来分析...
"researching-education-front"项目便是这样一个实例,它利用Gatsby为高等教育领域的教师和教育研究人员打造了一个专业的新闻通讯平台——researchingeducation.com。 Gatsby是一款基于React的开源框架,专为创建...
You are an expert in writing and researching, specializing in persuasive and informative pieces of work. You have helped many people before me to create persuasive and informative pieces of work for ...
Our team overcame challenges, researching online and in libraries, using Petrel and Eclipse for modeling. Our efforts were rewarded with an Excellence Award. Moreover, I'm known for my persistence. ...
CMMI researching Institute 版权所有,未经授权不得复制、拷贝、复印、出售、转售、分配、转让 CMMI 内容的任何部分或创建衍生作品。 版本变更历史: 版本 2.0:初始基线发布 版本 2.1:更新了信息,包括“开发、...
例如:“After researching [Company Name], I am deeply impressed by its commitment to innovation and customer satisfaction. I am eager to bring my unique blend of skills and enthusiasm to contribute to...
I had been researching parallel programming, multiprocessor, and multicore since 1997, so I couldn’t help installing the fi rst CTP and trying it. It was obvious that it was going to be an exciting ...
Android-OpenGL-1.0-Test: Android app that uses OpenGL ES 1.0 used for researching OpenGL ES for Android
In the last two years, she has been spending a huge amount of time working on and researching the subject. She’s been sharing her insights with people through articles, workshops, and projects. Alla...
- 作为及物动词,表示“从事……的研究”,例如:“The scientists are researching the modern movies.”(科学家们正在研究现代电影。) 3. **whatever**: - 作为连词,表示“不论什么”,常引导从句,可以...