View MySQL table footprint

If you want to know the space occupied by each table in the MySQL database and the number of rows recorded in the table, you can open the information_schema database of MySQL. There is a TABLES table in the library. The main fields of this table are: TABLE_SCHEMA: database name TABLE_NAME: table name ENGINE: storage engine used TABLES_ROWS: number of records DATA_LENGTH: data size INDEX_LENGTH: index size
1. Go in and specify the schema database:
      > use information_schema;
2. Query the size of all data:
      > select concat(round(sum(DATA_LENGTH/1024/1024), 2), 'MB') as data from TABLES;
3. View the size of the specified database instance:
     > select concat(round(sum(DATA_LENGTH/1024/1024), 2), 'MB') as data from TABLES where table_schema='db_name';
4. View the size of the table of the specified database: 
     > select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='db_name' and table_name='tb_name';
 
Example:
//Go to MySQL's own management library: information_schema //Your own database: abig //Your own table: t_teacher
//The result obtained is in bytes, dividing by 1024 is K, dividing by 1048576 is M.
mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB, -> concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB -> from tables where -> table_schema='abig' -> and table_name = 't_teacher';

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326125704&siteId=291194637