Loading compressed file into mysql without uncompressing

If you have a compressed file from a mysqldump backup of your mysql database, and you don’t have space to uncompress it to load it on another machine.  You can load it directly from the compress file using this command:

zcat backupdump.sql.gz | mysql -uusername -p databasename

This will uncompress the file on the fly without using the space to hold the uncompressed file.

NOTE: You can create a compressed on the fly backup of a table by doing this command:

mysqldump -uuser -ppass dbname tablename | gzip – > backupdump.sql.gz

Leave out the tablename to dump the entire database..

I run this command in backup scripts for all my databases every night from cron.

These backup scripts typically look like this to name the file using todays date:

#!/bin/bash

cd /backupdirectory

DAY=`date ‘+%m%d%y’`

OUTFILE=”dataabasename.dmp.sql.$DAY.gz”

mysqldump -uuser -ppass dbname | gzip – > $OUTFILE

scp $OUTFILE remoteserverforsafekeeping.com:/backups

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published.