HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMajor

How can I determine the size of a dump file prior to dumping?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
dumpcanthefiledumpingpriorsizedeterminehow

Problem

How can I determine or estimate the size of the SQL dump file prior to using something like mysqldump?

Solution

Please run this query:

SELECT
    Data_BB / POWER(1024,1) Data_KB,
    Data_BB / POWER(1024,2) Data_MB,
    Data_BB / POWER(1024,3) Data_GB
FROM (SELECT SUM(data_length) Data_BB FROM information_schema.tables
WHERE table_schema NOT IN ('information_schema','performance_schema','mysql')) A;


This will give you a ballpark figure. The column index_length is not used because mysqldump does not dump indexes, only data. Just to be safe, you should always gzip it immediately:

mysqldump --all-databases --routines --triggers | gzip > MySQLData.sql.gz


Give it a Try !!!

Code Snippets

SELECT
    Data_BB / POWER(1024,1) Data_KB,
    Data_BB / POWER(1024,2) Data_MB,
    Data_BB / POWER(1024,3) Data_GB
FROM (SELECT SUM(data_length) Data_BB FROM information_schema.tables
WHERE table_schema NOT IN ('information_schema','performance_schema','mysql')) A;
mysqldump --all-databases --routines --triggers | gzip > MySQLData.sql.gz

Context

StackExchange Database Administrators Q#37159, answer score: 39

Revisions (0)

No revisions yet.