Mysql – Database schema size result differs from file size when exported

database-sizeexportMySQLschema

I used this query to find out my database 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 ;

it returned as 849MB but when I exported the database it was only 501MB.

Being that there seemed to be over 300MB of info missing I decided to export in parts all the a,b,c etc, once done the total size of the folder the parts where stored in it was 606MB

This was better 100MB more but that still leaves around 200MB unaccounted for, I didn't export as zip or gzip archive just straight .sql file so really it should not differ and when the difference is over 200MB I'm thinking there is something wrong but I haven't a clue what or why each try returns a different size …

…any suggestions on why this is happening?

Best Answer

The export does not contain the indexes. It only contains the definition of the indexes but not the data that is stored in there.

Additionally the size of SQL export will also not reflect the size of your data (just think of the SQL keywords that are needed for the SQL export).

When you move data from one representation to another (MySQL "on-disk" format -> Binary Export -> SQL Script) it is to be expected that the different formats show a different size.

But I don't understand what you problem actually is.