SQL statement to see the size of disk space occupied by each database in mysql

1. Select information_schema

Use information_schema

2. Query the size of disk space occupied by all databases

Select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2), 'MB') as data_size,
Concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
From information_schema.tables
Group by TABLE_SCHEMA
Order by data_length desc;

3. Query the size of disk space occupied by a single database

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;

reprinted the original text:SQL statement to see the size of disk space occupied by each database in mysql - CodeDay