天天看點

mysql查詢整個表語句_mysql查詢整個庫和單表狀态的語句

查整個庫的狀态:

select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,

concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,

concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,

concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size

from information_schema.tables

where TABLE_SCHEMA = 'databasename';

查單表:

select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,

concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,

concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,

concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size

from information_schema.tables

where TABLE_NAME = 'tablename';

查詢某個庫中所有表的大小:

select TABLE_NAME, concat(truncate(data_length/1024/1024,2),' MB') as data_size,

concat(truncate(index_length/1024/1024,2),' MB') as index_size

from information_schema.tables where TABLE_SCHEMA = 'DATABASE_NAME'

group by TABLE_NAME

order by data_length desc;