jersten jersten - 4 months ago 18
SQL Question

MySQL Query database size

Is there a query or function that I can use to determine the size of a database in MySQL? If not what is the typical way to find the size of database in MySQL?

I was googling and found

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%' ;


And it returns a database that I know is 400MB to be
474989023196466.25 MB
!

Answer

Try with 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 ;
Comments