Use SQL commands to view Mysql database, table size method

To know the size of each database , follow these steps:

1. Enter the information_schema database (stores the information of other databases)

use information_schema;

 

2. Query the size of all data:

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;

 

If there is an index, you need to add the index size to:

SELECT concat(round(sum(data_length/1024/1024),2),'MB') as data_size,concat(round(sum(INDEX_LENGTH/1024/1024),2),'MB') as index_size

FROM information_schema.tables 

 

3. View the size of the specified database:

For example, check the size of the database home

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home';

 

4. View the size of a table in the specified database

For example, check the size of the members table in the database home

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home' and table_name='members';

 

Detailed source reference: http://www.frostsky.com/2011/08/ MySQL -query-size/

 

Note: If the data has been deleted, but the space is not released, it may be caused by fragmentation. The solution:

http://daizj.iteye.com/blog/2255918

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326928830&siteId=291194637