Home >Database >Mysql Tutorial >How to check the database table capacity through MySQL

How to check the database table capacity through MySQL

jacklove
jackloveOriginal
2018-06-09 09:15:252111browse

This article introduces the MySQL command statement to check the capacity of the database table, and provides complete query statements and examples for everyone to learn and use.

1. Check the capacity of all databases

select table_schema as '数据库',sum(table_rows) as '记录数',sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'from information_schema.tablesgroup by table_schemaorder by sum(data_length) desc, sum(index_length) desc;

2. Check the capacity of each table in all databases

select table_schema as '数据库',
table_name as '表名',
table_rows as '记录数',truncate(data_length/1024/1024, 2) as '数据容量(MB)',truncate(index_length/1024/1024, 2) as '索引容量(MB)'from information_schema.tablesorder by data_length desc, index_length desc;

3. Check the capacity of the specified database

Example : Check the capacity of the mysql library

select table_schema as '数据库',sum(table_rows) as '记录数',sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'from information_schema.tableswhere table_schema='mysql';

How to check the database table capacity through MySQL

4. Check the capacity of each table in the specified database

Example: Check the capacity of each table of the mysql library

select table_schema as '数据库',
table_name as '表名',
table_rows as '记录数',truncate(data_length/1024/1024, 2) as '数据容量(MB)',truncate(index_length/1024/1024, 2) as '索引容量(MB)'from information_schema.tableswhere table_schema='mysql'order by data_length desc, index_length desc;

How to check the database table capacity through MySQL

This article explains how to check the database table capacity through MySQL. For more related content, please pay attention to the php Chinese website.

Related recommendations:

Explanation on how to use php str_getcsv to parse a string into an array

Optimize the client Call the server interface to reduce the request data capacity

mysql order by rand() efficiency optimization method

The above is the detailed content of How to check the database table capacity through MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn