MySQL database dump directly via SSH

I had a server with almost no disk space and i needed to move the site to another virtual server. Making a database dump locally was no option so I Googled around and found some handy commandline ways to copy the database to the other server.

Dump MySQL database gzipped via SSH to destination server:
mysqldump -uMYSQL_USERNAME -pMYSQL_PASSWORD DATABASE_NAME | gzip -c | ssh USERNAME@DESTINATION_HOST 'cat > ~/dump.sql.gz'

Dump MySQL database gzippped via SSH and import it on destination server:
mysqldump –opt –add-drop-table -Q -u localuser –p localdatabase |gzip -c |ssh remoteuser@remoteserver 'gunzip -c | mysql -u remoteuser –password=remotepassword remotedatabase'

No Comments »

Trackback URI | Comments RSS

Leave a Reply