Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7741795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:07:12+00:00 2026-06-01T09:07:12+00:00

Hi I am new to databases. I am working on huge database and trying

  • 0

Hi I am new to databases. I am working on huge database and trying to clear up the mess. I want to start by finding the top ten tables that take up highest memory in the whole database. I cannot go by finding memory of each table since there are too many tables. I need the top 10 or 20 tables that take up the maximum space. Any help would be much appreciated. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:07:13+00:00Added an answer on June 1, 2026 at 9:07 am

    MyISAM only takes up memory for its indexes

    To find the top 10 MyISAM tables that can use the most memory in the worst case try this:

    SELECT * FROM
    (
        SELECT table_schema,table_name,index_length
        FROM information_schema.tables
        WHERE engine='MyISAM' AND
        table_schema NOT IN ('information_schema','mysql','performance_schema')
        ORDER BY index_length DESC
    ) LIMIT 10;
    

    InnoDB takes up memory for its data and indexes

    To find the top 10 InnoDB tables that can use the most memory in the worst case try this:

    SELECT * FROM
    (
        SELECT table_schema,table_name,data_length+index_length tblsize
        FROM information_schema.tables
        WHERE engine='InnoDB'
        ORDER BY index_length DESC
    ) LIMIT 10;
    

    Here is another display of the top 50 tables by size descending

    SELECT * FROM
    (SELECT TN TableName,LPAD(REPLACE(FORMAT(TS/POWER(1024,1),2),',',''),Z,' ') KB,
    LPAD(REPLACE(FORMAT(TS/POWER(1024,2),2),',',''),Z,' ') MB,
    LPAD(REPLACE(FORMAT(TS/POWER(1024,3),2),',',''),Z,' ') GB
    FROM (SELECT CONCAT(table_schema,'.',table_name) TN,
    (data_length+index_length) TS FROM information_schema.tables
    WHERE table_schema NOT IN ('information_schema','mysql','performance_schema')
    AND engine IS NOT NULL) A,(SELECT 13 Z) B ORDER BY TS DESC) MMM LIMIT 50;
    

    If you are interested, I have queries that give you the whole story on the MySQL Instance

    This query shows you the amount of disk space taken by Storage Engine in GB

    SELECT IFNULL(B.engine,'Total') "Storage Engine",
    CONCAT(LPAD(REPLACE(FORMAT(B.DSize/POWER(1024,pw),3),',',''),17,' '),
    ' ',SUBSTR(' KMGTP',pw+1,1),'B') "Data Size",
    CONCAT(LPAD(REPLACE(FORMAT(B.ISize/POWER(1024,pw),3),',',''),17,' '),
    ' ',SUBSTR(' KMGTP',pw+1,1),'B') "Index Size", CONCAT(LPAD(REPLACE(
    FORMAT(B.TSize/POWER(1024,pw),3),',',''),17,' '),' ',
    SUBSTR(' KMGTP',pw+1,1),'B') "Table Size"
    FROM (SELECT engine,SUM(data_length) DSize,SUM(index_length) ISize,
    SUM(data_length+index_length) TSize FROM information_schema.tables
    WHERE table_schema NOT IN ('mysql','information_schema','performance_schema')
    AND engine IS NOT NULL GROUP BY engine WITH ROLLUP) B,(SELECT 3 pw) A ORDER BY TSize;
    

    This query shows you the amount of disk space taken by Database in GB

    SELECT DBName,CONCAT(LPAD(FORMAT(SDSize/POWER(1024,pw),3),17,' '),
    ' ',SUBSTR(' KMGTP',pw+1,1),'B') "Data Size",CONCAT(LPAD(FORMAT(SXSize/
    POWER(1024,pw),3),17,' '),' ',SUBSTR(' KMGTP',pw+1,1),'B') "Index Size",
    CONCAT(LPAD(FORMAT(STSize/POWER(1024,pw),3),17,' '),' ',
    SUBSTR(' KMGTP',pw+1,1),'B') "Total Size" FROM
    (SELECT IFNULL(DB,'All Databases') DBName,SUM(DSize) SDSize,
    SUM(XSize) SXSize,SUM(TSize) STSize FROM (SELECT table_schema DB,
    data_length DSize,index_length XSize,data_length+index_length TSize
    FROM information_schema.tables WHERE table_schema NOT IN
    ('mysql','information_schema','performance_schema')) AAA
    GROUP BY DB WITH ROLLUP) AA,(SELECT 3 pw) BB ORDER BY (SDSize+SXSize);
    

    This query shows you the amount of disk space taken by Database by Storage Engine in GB

    SELECT IF(ISNULL(B.table_schema)+ISNULL(B.engine)=2,"Storage for All Databases",
    IF(ISNULL(B.table_schema)+ISNULL(B.engine)=1,CONCAT("Storage for ",B.table_schema),
    CONCAT(B.engine," Tables for ",B.table_schema))) Statistic,CONCAT(LPAD(REPLACE(
    FORMAT(B.DSize/POWER(1024,pw),3),',',''),17,' '),' ',SUBSTR(' KMGTP',pw+1,1),'B')
    "Data Size",CONCAT(LPAD(REPLACE(FORMAT(B.ISize/POWER(1024,pw),3),',',''),17,' '),
    ' ',SUBSTR(' KMGTP',pw+1,1),'B') "Index Size",CONCAT(LPAD(REPLACE(FORMAT(B.TSize/
    POWER(1024,pw),3),',',''),17,' '),' ',SUBSTR(' KMGTP',pw+1,1),'B') "Table Size"
    FROM (SELECT table_schema,engine,SUM(data_length) DSize,SUM(index_length) ISize,
    SUM(data_length+index_length) TSize FROM information_schema.tables WHERE
    table_schema NOT IN ('mysql','information_schema','performance_schema')
    AND engine IS NOT NULL GROUP BY table_schema,engine WITH ROLLUP) B,
    (SELECT 3 pw) A ORDER BY TSize;
    

    The three previous queries I posted has a common feature : the subquery (SELECT 3 pw)

    • If you use (SELECT 0 pw), report is in Bytes
    • If you use (SELECT 1 pw), report is in KiloBytes
    • If you use (SELECT 2 pw), report is in MegaBytes
    • If you use (SELECT 3 pw), report is in GigaBytes
    • If you use (SELECT 4 pw), report is in TeraBytes
    • If you use (SELECT 5 pw), report is in PetaBytes (If you need this, post that result please !!!)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a new application that uses a jet (MS Access) database.
I'm very new to working with databases in C# (but not C# itself) and
I'm fairly new to working with relational databases, but have read a few books
Working on joining up two legacy DB systems into new database where I can
I am working on making a new SQLite database. Obviously for a number of
I'm rather new to working with multiple threads in a database (most of my
I am bit new to C#. I am working on a Database application and
I am working on sql server monitoring product and i have database query that
I am a little lost being new to databases. I am trying to create
I've been working with databases for a long time but I'm new to query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.