当前位置:网站首页>How to view the occupied space of a table in MySQL database

How to view the occupied space of a table in MySQL database

2022-06-10 21:51:00 1024 Q

Catalog

Preface

1、 Switch database

2、 View all database capacity sizes

3、 View specified database usage size

4、 View table usage size

5、 View all database capacity sizes

6、 Check the capacity of all databases

7、 View the specified database capacity size

8、 Check the capacity of each table in the specified database

summary

Preface

CentOS7 install MySQL8 The detailed steps

CentOS7 In the environment MySQL Common commands

stay mysql There is a default data table in information_schema,information_schema This data sheet is saved MySQL Information about all the databases on the server . Such as database name , Table of database , Data type and access right of table column . It's simpler , The machine MySQL Server , What kind of databases are there 、 What are the tables in each database , What is the field type of each table , What permissions do you need to access each database , And so on, information is stored in information_schema Inside the watch , So please don't delete this table .

1、 Switch database use information_schema;2、 View all database capacity sizes selecttable_schema as ' database ',sum(table_rows) as ' Record number ',sum(truncate(data_length/1024/1024, 2)) as ' Data capacity (MB)',sum(truncate(index_length/1024/1024, 2)) as ' Index capacity (MB)'from information_schema.tablesgroup by table_schemaorder by sum(data_length) desc, sum(index_length) desc;3、 View specified database usage size

short_video Library name video_info Table name

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='short_video';4、 View table usage size

video_info Table name

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='short_video' and table_name='video_info';5、 View all database capacity sizes selecttable_schema as ' database ',sum(table_rows) as ' Record number ',sum(truncate(data_length/1024/1024, 2)) as ' Data capacity (MB)',sum(truncate(index_length/1024/1024, 2)) as ' Index capacity (MB)'from information_schema.tablesgroup by table_schemaorder by sum(data_length) desc, sum(index_length) desc;6、 Check the capacity of all databases selecttable_schema as ' database ',table_name as ' Table name ',table_rows as ' Record number ',truncate(data_length/1024/1024, 2) as ' Data capacity (MB)',truncate(index_length/1024/1024, 2) as ' Index capacity (MB)'from information_schema.tablesorder by data_length desc, index_length desc;7、 View the specified database capacity size selecttable_schema as ' database ',sum(table_rows) as ' Record number ',sum(truncate(data_length/1024/1024, 2)) as ' Data capacity (MB)',sum(truncate(index_length/1024/1024, 2)) as ' Index capacity (MB)'from information_schema.tableswhere table_schema='short_video';8、 Check the capacity of each table in the specified database selecttable_schema as ' database ',table_name as ' Table name ',table_rows as ' Record number ',truncate(data_length/1024/1024, 2) as ' Data capacity (MB)',truncate(index_length/1024/1024, 2) as ' Index capacity (MB)'from information_schema.tableswhere table_schema='short_video'order by data_length desc, index_length desc; summary

This is about MySQL This is the end of the article on how to view the table occupied space in the database , More about MySQL To view the table's occupied space, please search the previous articles of the software development network or continue to browse the following related articles. I hope you can support the software development network in the future !


原网站

版权声明
本文为[1024 Q]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206102028062422.html