Skip to content

Instantly share code, notes, and snippets.

@silviud
Last active August 29, 2015 13:56
Show Gist options
  • Save silviud/9331645 to your computer and use it in GitHub Desktop.
Save silviud/9331645 to your computer and use it in GitHub Desktop.
MySQL Infos
/* index size per db */
SELECT DBName,CONCAT(LPAD(FORMAT(SDSize/POWER(1024,pw),3),17,' '),' ',
SUBSTR(' KMGTP',pw+1,1),'B') "Data Size",CONCAT(LPAD(
FORMAT(SXSize/POWER(1024,pw),3),17,' '),' ',SUBSTR(' KMGTP',pw+1,1),'B') "Index Size",
CONCAT(LPAD(FORMAT(STSize/POWER(1024,pw),3),17,' '),' ',
SUBSTR(' KMGTP',pw+1,1),'B') "Total Size" FROM
(SELECT IFNULL(DB,'All Databases') DBName,SUM(DSize) SDSize,SUM(XSize) SXSize,
SUM(TSize) STSize FROM (SELECT table_schema DB,data_length DSize,
index_length XSize,data_length+index_length TSize FROM information_schema.tables
WHERE table_schema NOT IN ('mysql','information_schema','performance_schema')) AAA
GROUP BY DB WITH ROLLUP) AA,(SELECT 3 pw) BB ORDER BY (SDSize+SXSize);
/* index size per engine */
SELECT IFNULL(B.engine,'Total') "Storage Engine",
CONCAT(LPAD(REPLACE(FORMAT(B.DSize/POWER(1024,pw),3),',',''),17,' '),' ',
SUBSTR(' KMGTP',pw+1,1),'B') "Data Size", CONCAT(LPAD(REPLACE(
FORMAT(B.ISize/POWER(1024,pw),3),',',''),17,' '),' ',
SUBSTR(' KMGTP',pw+1,1),'B') "Index Size", CONCAT(LPAD(REPLACE(
FORMAT(B.TSize/POWER(1024,pw),3),',',''),17,' '),' ',
SUBSTR(' KMGTP',pw+1,1),'B') "Table Size" FROM
(SELECT engine,SUM(data_length) DSize,SUM(index_length) ISize,
SUM(data_length+index_length) TSize FROM
information_schema.tables WHERE table_schema NOT IN
('mysql','information_schema','performance_schema') AND
engine IS NOT NULL GROUP BY engine WITH ROLLUP) B,
(SELECT 3 pw) A ORDER BY TSize;
/* top io usage per table */
select * from performance_schema.file_summary_by_instance order by COUNT_READ desc limit 10;
/* top io usage for specific table - like */
select * from performance_schema.file_summary_by_instance where FILE_NAME like '%TABLE%' order by COUNT_READ DESC limit 10;
/* io waits per table - ver >= 5.6 */
select * from performance_schema.table_io_waits_summary_by_table where OBJECT_NAME='TABLE';
/* top io waits per table - ver >= 5.6 */
select OBJECT_NAME,COUNT_STAR from performance_schema.table_io_waits_summary_by_table order by COUNT_STAR DESC LIMIT 5;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment