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

Detailed steps to install nginx on Apple M1 chip and deploy vue project

brew install nginx Apple Mac uses brew to install...

About VUE's compilation scope and slot scope slot issues

What are slots? The slot directive is v-slot, whi...

Comparison of several examples of insertion efficiency in Mysql

Preface Recently, due to work needs, I need to in...

Essential Handbook for Web Design 216 Web Safe Colors

The color presentation on a web page will be affec...

centos7.2 offline installation mysql5.7.18.tar.gz

Because of network isolation, MySQL cannot be ins...

Usage and principles of provide and inject in Vue3

Preface: When passing data between parent and chi...

Detailed explanation of Angular routing basics

Table of contents 1. Routing related objects 2. L...

Analysis and solution of abnormal problem of loading jar in tomcat

Description of the phenomenon: The project uses s...

Explain how to analyze SQL efficiency

The Explain command is the first recommended comm...

js precise calculation

var numA = 0.1; var numB = 0.2; alert( numA + num...

Tutorial on installing MySQL under Linux

Table of contents 1. Delete the old version 2. Ch...

Web Design: When the Title Cannot Be Displayed Completely

<br />I just saw the newly revamped ChinaUI....