How to get size of mysql database?

前端 未结 9 1831
栀梦
栀梦 2020-11-27 08:43

How to get size of a mysql database?
Suppose the target database is called \"v3\".

相关标签:
9条回答
  • 2020-11-27 09:19

    To get a result in MB:

    SELECT
    SUM(ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024), 2)) AS "SIZE IN MB"
    FROM INFORMATION_SCHEMA.TABLES
    WHERE
    TABLE_SCHEMA = "SCHEMA-NAME";
    

    To get a result in GB:

    SELECT
    SUM(ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024 / 1024), 2)) AS "SIZE IN GB"
    FROM INFORMATION_SCHEMA.TABLES
    WHERE
    TABLE_SCHEMA = "SCHEMA-NAME";
    
    0 讨论(0)
  • 2020-11-27 09:29
    mysqldiskusage  --server=root:MyPassword@localhost  pics
    
    +----------+----------------+
    | db_name  |         total  |
    +----------+----------------+
    | pics     | 1,179,131,029  |
    +----------+----------------+
    

    If not installed, this can be installed by installing the mysql-utils package which should be packaged by most major distributions.

    0 讨论(0)
  • 2020-11-27 09:31

    If you want the list of all database sizes sorted, you can use :

    SELECT * 
    FROM   (SELECT table_schema AS `DB Name`, 
               ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS `DB Size in MB`
            FROM   information_schema.tables 
            GROUP  BY `DB Name`) AS tmp_table 
    ORDER  BY `DB Size in MB` DESC; 
    
    0 讨论(0)
提交回复
热议问题