How to get size of mysql database?

前端 未结 9 1830
栀梦
栀梦 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:12

    It can be determined by using following MySQL command

    SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema
    

    Result

    Database    Size (MB)
    db1         11.75678253
    db2         9.53125000
    test        50.78547382
    

    Get result in GB

    SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 / 1024 AS "Size (GB)" FROM information_schema.TABLES GROUP BY table_schema
    
    0 讨论(0)
  • 2020-11-27 09:12

    Alternatively, if you are using phpMyAdmin, you can take a look at the sum of the table sizes in the footer of your database structure tab. The actual database size may be slightly over this size, however it appears to be consistent with the table_schema method mentioned above.

    Screen-shot :

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

    Run this query and you'll probably get what you're looking for:

    SELECT table_schema "DB Name",
            ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" 
    FROM information_schema.tables 
    GROUP BY table_schema; 
    

    This query comes from the mysql forums, where there are more comprehensive instructions available.

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

    Go into the mysql data directory and run du -h --max-depth=1 | grep databasename

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

    Alternatively you can directly jump into data directory and check for combined size of v3.myd, v3. myi and v3. frm files (for myisam) or v3.idb & v3.frm (for innodb).

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

    First login to MySQL using

    mysql -u username -p

    Command to Display the size of a single Database along with its table in MB.

    SELECT table_name AS "Table",
    ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
    FROM information_schema.TABLES
    WHERE table_schema = "database_name"
    ORDER BY (data_length + index_length) DESC;
    

    Change database_name to your Database

    Command to Display all the Databases with its size in MB.

    SELECT table_schema AS "Database", 
    ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" 
    FROM information_schema.TABLES 
    GROUP BY table_schema;
    
    0 讨论(0)
提交回复
热议问题