How to Check the Size of All Databases on a cPanel Server

April 25, 2025 / Sales FAQ

If you’re managing a cPanel server and need to view the sizes of all MySQL databases, a quick MySQL query can give you the correct insights. This is particularly helpful for identifying large databases that might require optimization or cleanup.

Follow the guide:
Finding the 20 Largest Databases

  1. Access Your Server:
    1.  Log in to your WHM panel.
    2. Go to WHM > Terminal, or connect via SSH using your preferred client.
      terminal
    3. Run the MySQL Query:
      Execute the following command:

      mysql -e “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
      ORDER BY SUM(data_length + index_length) DESC
      LIMIT 20;”
  2. Understanding the Output
    The query will return a list of the top 20 databases, sorted by size in megabytes (MB). The output will look something like this:

    Database Size (MB)
    big_database_1   50
    big_database_2   950.75
    user_site_db     820.20
  3. To List All Databases (Not Just Top 20)
    Simply remove the LIMIT 20; clause to list every database:

    mysql -e “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
    ORDER BY SUM(data_length + index_length) DESC;”

    Alternative Method: Check Disk Usage
    For a quick, file-based check, use the du command:

    du -sh /var/lib/mysql/* | sort -hr | head -20

    Note: This method may be inaccurate for InnoDB databases since they store data in shared tablespaces.

You can use this method to view the size of all databases on a cPanel server. If you need further assistance, our support team is here to help.

Ready to set up a new database? Learn How to create a MySQL database in cPanel

Spread the love