How can I determine by database size in MySQL?

352430 pts.
Tags:
MySQL
MySQL Database
Does anyone know if there's a specific query or function that can determine the size of my database in MySQL? If there isn't one, what's the best way to go about it? I tried this and it came up with 474989023196466.25 MB (even though I know the database is 400 MB).
SELECT CONCAT(sum(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024),2))," MB") AS Size FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA like '%YOUR_DB_NAME%' ;

Answer Wiki

Thanks. We'll let you know when a new response is added.
Hi,

Sum up the data_length + index_length is equal to the total table size.

data_length – store the real data.
index_length – store the table index.
Here’s the SQL script to list out the entire databases size

SELECT table_schema “Data Base Name”, SUM( data_length + index_length) / 1024 / 1024 
“Data Base Size in MB” FROM information_schema.TABLES GROUP BY table_schema ;
Another SQL script to list out one database size, and each tables size in detail

SELECT TABLE_NAME, table_rows, data_length, index_length, 
round(((data_length + index_length) / 1024 / 1024),2) “Size in MB”
FROM information_schema.TABLES WHERE table_schema = “schema_name”;

Thanks & Regards
Clark Kent

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Brijesh
    Hi,

    Try this query :

    SELECT table_schema AS "Data Base Name", 
    sum( data_length + index_length ) / 1024 / 1024 AS "Data Base Size in MB" 
    FROM information_schema.TABLES GROUP BY table_schema ;

    Or with this, if you want to ROUND :

    SELECT table_schema AS "Data Base Name", 
    ROUND(SUM( data_length + index_length ) / 1024 / 1024, 2) AS "Data Base Size in MB" 
    FROM information_schema.TABLES GROUP BY table_schema ;
    9,870 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following