dak ブログ

python、rubyなどのプログラミング、MySQL、サーバーの設定などの備忘録。レゴの写真も。

mysqlのテーブル情報

2010-12-14 00:34:51 | mysql
mysqlのテーブルサイズなどを取得する方法です。
行数を一気に取得できるので便利です。

【SQL】
select
table_schema db
, table_name tbl
, concat(round(table_rows/1000, 2),'k') rows
, concat(round(data_length/(1024*1024), 2),'M') data
, concat(round(index_length/(1024*1024), 2),'M') idx
, concat(round((data_length+index_length)/(1024*1024), 2),'M') total_size
from
information_schema.TABLES
order by
db asc
, tbl asc
;

【実行結果】
db tbl rows data idx total_size
db1 tbl1 490.50k 100.63M 39.67M 140.30M
db1 tbl2 1215.99k 72.69M 76.75M 149.44M