3

I have a recent.sql.gz file on a remote server. What I try to accomplish is the following: I want to open the file, push the content over SSH to my local machine, use zcat to uncompress the content and pipe it to mysql. Something like this:

ssh user@remote 'cat recent.sql.gz' | zcat | mysql
4
  • 6
    and what's the problem? Commented Jan 3, 2017 at 10:21
  • 1
    oh well, ehm.. didn't test it. i thought it can't be that easy.
    – Aley
    Commented Jan 3, 2017 at 10:48
  • provided recent.sql.gz is in HOME dir of user on remote, and ssh work password less-ly, this should work.
    – Archemar
    Commented Jan 3, 2017 at 10:52
  • Alright then :)
    – Aley
    Commented Jan 3, 2017 at 10:53

1 Answer 1

0

Your answer is

ssh user@remote 'cat recent.sql.gz' | zcat | mysql

Thank you to @Aley above :)

2
  • Unless there is a real reason to transfer the file compressed: ssh user@remote 'gzip -c -d recent.sql.gz' | mysql
    – Kusalananda
    Commented Jan 31, 2022 at 15:47
  • I thought about that too. Typically, CPU's and memory are faster than the network, and average sql is very compressible (if you're not storing pre-compressed blobs, of course). So compressing, transferring, and uncompressing should (in year 2022) be faster than sending an uncompressed file across a network. Future network tech may prove us wrong - but I wouldn't bet on it yet.
    – FlipMcF
    Commented Feb 11, 2022 at 20:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .