Example of how to check the capacity of MySQL database table

Example of how to check the capacity of MySQL database table

This article introduces the command statements for checking the capacity of database tables in MySQL, and provides complete query statements and examples for easy learning and use.

1. View the capacity of all databases

select 
table_schema as 'database',
sum(table_rows) as 'Number of records',
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.tables
group by table_schema
order by sum(data_length) desc, sum(index_length) desc;

2. View the capacity of all database tables

select 
table_schema as 'database',
table_name as 'table name',
table_rows as 'number of records',
truncate(data_length/1024/1024, 2) as 'Data capacity (MB)',
truncate(index_length/1024/1024, 2) as 'Index capacity (MB)'
from information_schema.tables
order by data_length desc, index_length desc;

3. Check the capacity of the specified database

Example: Check the capacity of the mysql database

select 
table_schema as 'database',
sum(table_rows) as 'Number of records',
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.tables
where table_schema='mysql'; 

這里寫圖片描述

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

Example: Check the capacity of each table in the MySQL database

select 
table_schema as 'database',
table_name as 'table name',
table_rows as 'number of records',
truncate(data_length/1024/1024, 2) as 'Data capacity (MB)',
truncate(index_length/1024/1024, 2) as 'Index capacity (MB)'
from information_schema.tables
where table_schema='mysql'
order by data_length desc, index_length desc; 

這里寫圖片描述

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of MySQL database binlog cleanup command
  • MySQL Database Iron Laws (Summary)
  • How to compare two database table structures in mysql
  • Method of using MySQL system database for performance load diagnosis
  • mysql create database, add users, user authorization practical method

<<:  Native js to achieve puzzle effect

>>:  When setting up Jenkins in Docker environment, the console log shows garbled Chinese characters when building tasks

Recommend

Linux file systems explained: ext4 and beyond

Today I will take you through the history of ext4...

How to install pip package in Linux

1. Download the pip installation package accordin...

CSS achieves the effect of aligning multiple elements at both ends in a box

The arrangement layout of aligning the two ends o...

Vue integrates PDF.js to implement PDF preview and add watermark steps

Table of contents Achieve results Available plugi...

Installation and configuration method of vue-route routing management

introduce Vue Router is the official routing mana...

What qualities should a good advertisement have?

Some people say that doing advertising is like bei...

Designing the experience: What’s on the button

<br />Recently, UCDChina wrote a series of a...

Problems with index and FROM_UNIXTIME in mysql

Zero, Background I received a lot of alerts this ...

Express implements login verification

This article example shares the specific code for...

Analysis of the event loop mechanism of js

Preface As we all know, JavaScript is single-thre...

Detailed process of installing nginx1.9.1 on centos8

1.17.9 More delicious, really Nginx download addr...

How to create a MySQL master-slave database using Docker on MacOS

1. Pull the MySQL image Get the latest MySQL imag...