mysqldump via SSH to local computer

这一生的挚爱 提交于 2020-04-08 04:36:43

问题


I have an SSH access to production server of the Rails app.

I want to make a mysqldump of production database to my Mac. Please help me to achieve this.


回答1:


Direct method to dump mysql data from remote server to your local computer is:

ssh root@ipaddress "mysqldump -u dbuser -p dbname | gzip -9" > dblocal.sql.gz 

Or

ssh -l root ipaddress "mysqldump -u dbuser -p dbname | gzip -9" > dblocal.sql.gz

Both command does the same work.

If you have password for ssh and database access there will two prompt for password or if you have no password for ssh then you will be asked to enter you database password.

Similarly, if you are using key from aws or cloud other service you can incorporate the key in the command as:

ssh -i key.pem root@ipaddress "mysqldump -u dbuser -p dbname | gzip -9" > dblocal.sql.gz



回答2:


  1. Connect to server via ssh: ssh remote_username@remote_host
  2. Go to 'current' folder
  3. Make a dump: mysqldump -u username -ppassword -h host database > dump.sql
  4. Disconnect from server
  5. Copy a dump.sql file to local computer: scp remote_username@remote_host:/path/to/dump.sql /Users/YourName/Documents/dump.sql
  6. Connect to server via ssh again and go to 'current' folder
  7. Remove dump.sql file: rm dump.sql


来源:https://stackoverflow.com/questions/40024280/mysqldump-via-ssh-to-local-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!