Search code examples
mysqlamazon-web-servicesamazon-ec2rds

Mysql Dump RDS Trough Ec2 Instance


I'm trying to download a sql dump of my MySQL database in RDS through my local terminal. I have security groups setup so that only my ec2 instances can access this RDS database. Is there a way to run the mysqldump command all in one line w/o having to ssh into the Ec2 box > run command there > then scp the dump out to my local machine?

Command I normally run inside ec2 instance is

mysqldump DBNAME -h RDSURL -u USERNAME -p -P PORT > ~/dump.sql

Solution

  • I ended up solving this by setting up port forwarding per Mark B's advice. In one terminal window I did

     ssh -N -L 1234:RDSURL:PORT EC2USER@EC2URL -i LOCALPEMKEY
    

    Then in 2nd terminal window I did

     mysqldump DBNAME -h 127.0.0.1 -u USERNAME -p -P 1234 > ~/dump.sql
    

    Worked like a charm. Thanks for pointing me in the right direction Mark B.