Home > Database > Mysql Tutorial > How to query database capacity in mysql

How to query database capacity in mysql

藏色散人
Release: 2023-03-25 17:22:23
Original
6394 people have browsed it

Mysql method to query database capacity: 1. Open the DOS window, and then enter the bin directory of mysql; 2. Execute "SELECT table_schema AS 'shujuku', table_name AS 'biaoming', table_rows AS 'jilushu', TRUNCATE (data_length / 1024 / 1024, 2) ..." statement can be used to view the capacity of each table in all databases.

How to query database capacity in mysql

The operating environment of this tutorial: Windows 10 system, MySQL version 5.7, Dell G3 computer.

How to query the database capacity with mysql?

MySql View database and table capacity and sort

MySql View database and table capacity and sort View all database capacities

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. TABLES
GROUP BY
    table_schema
ORDER BY
    sum(data_length) DESC,
    sum(index_length) DESC;
Copy after login

View all database table capacities

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. TABLES
ORDER BY
    data_length DESC,
    index_length DESC;
Copy after login

View the capacity of the specified database

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.tables where table_schema = 'your_table_name';
Copy after login

View the capacity of each table in the specified database

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.TABLES 
WHERE
    table_schema = '指定的库名' 
ORDER BY
    data_length DESC,
    index_length DESC;
Copy after login

Recommended study: "MySQL Video Tutorial"

The above is the detailed content of How to query database capacity in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template