MySQL View the size of the database, table footprint

Source: Internet
Author: User

• View the size of each library

The code is as follows Copy Code

SELECT SUM (data_length) +sum (index_length) from information_schema.tables WHERE table_schema= ' database_name ';

The result is in bytes, except that 1024 is K, except that 1048576 is M.

• View the size of each table

The code is as follows Copy Code

SELECT table_name,data_length+index_length,table_rows from Information_schema.tables WHERE table_schema= ' Database_ Name ' and table_name= ' table_name ';

• View the last modified time of the table

The code is as follows Copy Code

SELECT table_name,update_time from Information_schema.tables where table_schema= ' database_name ';
LOG

The TABLES table for the INFORMATION_SCHEMA library, the main fields are:

Table_schema: Database name
TABLE_NAME: Table name
Engine: the storage engine used
Tables_rows: Number of records
Data_length: Data size
Index_length: Index size

An instance of your own application

The code is as follows Copy Code

Advanced go to MySQL comes with management library: INFORMATION_SCHEMA
Own database: Dbwww58com_kuchecarlib
Own table: T_carmodelparamvalue

mysql> use INFORMATION_SCHEMA;
Database changed
Mysql> Select Data_length,index_length
-From tables where
-Table_schema= ' Dbwww58com_kuchecarlib '
and table_name = ' t_carmodelparamvalue ';
+-------------+--------------+
| Data_length | Index_length |
+-------------+--------------+
|    166379520 | 235782144 |
+-------------+--------------+
1 row in Set (0.02 sec)

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= ' Dbwww58com_kuchecarlib '
and table_name = ' t_carmodelparamvalue ';
+----------------+-----------------+
| DATA_LENGTH_MB | INDEX_LENGTH_MB |
+----------------+-----------------+
| 158.67MB | 224.86MB |
+----------------+-----------------+
1 row in Set (0.03 sec)

MySQL View the size of the database, table footprint

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.