Mysql query database capacity method steps

Mysql query database capacity method steps

Query the total size of all databases

Here’s how:

mysql> use information_schema;
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES;
+-----------+
| data |
+-----------+
| 3052.76MB |
+-----------+
1 row in set (0.02 sec)

Count the amount of data in all libraries

The amount of data in each table = AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH

SELECT
SUM(AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH)/1024/1024 AS total_mb
FROM information_schema.TABLES

Statistics of each library size:

SELECT
table_schema,SUM(AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH)/1024/1024 AS total_mb
FROM information_schema.TABLES group by table_schema;

The second case: Check the size of the specified database, for example: database test, the method is as follows:

mysql> use information_schema;
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='test';
+----------+
| data |
+----------+
| 142.84MB |
+----------+
1 row in set (0.00 sec)

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;

Off-topic methods

Directly use shell commands to count the size of the mysql data directory (note that only the library is included, not the database log size)

Remark:

data_length: storage data size

data_length/1024/1024: Convert bytes to MB

round(sum(data_length/1024/1024),2): round to two decimal places

concat(round(sum(data_length/1024/1024),2),'MB') : Add the unit "MB" to the calculation result

This is the end of this article about the method and steps of Mysql query database capacity. For more relevant content about Mysql query database capacity, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to query date and time in mysql
  • MySQL database advanced query and multi-table query
  • A brief discussion on the implementation of fuzzy query using wildcards in MySQL
  • A brief discussion on using Cartesian product principle to query multiple tables in MySQL
  • Several implementation methods and advantages and disadvantages of SQL paging query in MySQL
  • An article to master MySQL index query optimization skills
  • Python pymysql link database query results converted to Dataframe instance
  • A brief discussion on the problem of passing parameters when using in in pymysql query statements
  • Example of how to retrieve the latest data using MySQL multi-table association one-to-many query
  • MySQL query syntax summary

<<:  How to solve the problem that Docker container has no vim command

>>:  JavaScript parseInt() and Number() difference case study

Recommend

Design reference WordPress website building success case

Each of these 16 sites is worth reading carefully,...

Mysql master-slave synchronization Last_IO_Errno:1236 error solution

What is the reason for the Last_IO_Errno:1236 err...

What are the advantages of using B+Tree as an index in MySQL?

Table of contents Why do databases need indexes? ...

How to set Tomcat as an automatically started service? The quickest way

Set Tomcat to automatically start the service: I ...

Reasons and methods for Waiting for table metadata lock in MySQL

When MySQL performs DDL operations such as alter ...

Nginx load balancing algorithm and failover analysis

Overview Nginx load balancing provides upstream s...

Detailed explanation of the specific use of the ENV instruction in Dockerfile

1. The ENV instruction in the Dockerfile is used ...

Tutorial on installing MySQL8 compressed package version on Win10

1 Download MySQL8 from the official website and i...

Two ways to correctly clean up mysql binlog logs

mysql correctly cleans up binlog logs Preface: Th...

Solution to the problem of repeated triggering of functions in Vue project watch

Table of contents Problem description: Solution 1...

Media query combined with rem layout in CSS3 to adapt to mobile screens

CSS3 syntax: (1rem = 100px for a 750px design) @m...

Example of converting JavaScript flat array to tree structure

Table of contents 10,000 pieces of data were lost...

How to install FastDFS in Docker

Pull the image docker pull season/fastdfs:1.2 Sta...