Snippet: Copy MySQL Databases Over SSH
14 Jul 2008 in Accelerator, MySQL, Programming by GarrickI needed to copy a database and the idea of backing it up just to re-import1 seemed like double the work. Here’s a snippet to pipe a mysqldump into a remote database. Keep an eye on the user names and passwords – you’ll need 3 sets; one for the database your copying, one to get into your remote server, and one for the remote, target database.
mysqldump -v -uUSER -pPASSWORD --opt --compress DATABASE_NAME | ssh REMOTE_SERVER_USER@REMOTE_HOSTNAME mysql -uREMOTE-MYSQL-USER -pREMOTE_MYSQL_PASSWORD REMOTE_DATABASE_NAME
1. Backing up is a good thing. Why aren’t you doing it? Here’s a script for that.
mysqldump -h HOSTNAME DATABASE_NAME | gzip -9 > BACKUP_DIR/DATABASE_NAME.sql.gz
Comments (2)
wdbp added these pithy words on Jul 16 08 at 10:29 amI’d said more : don’t use password on command line or erase history after…
Steven added these pithy words on May 19 09 at 11:42 amI’m trying to the reverse of this command but the remote server is not registering the password.
mysql -u USER -pPASSWORD DATABASE_NAME | ssh USER@REMOTE_HOSTNAME mysqldump -v -u USER -pPASSWORD -h HOST --opt --compress DATABASE_NAMEI am prompted for my ssh password. After entering it and pressing return, nothing happens. If I hit return again, it tells my my password is incorrect, when I know it’s not.
If I break the command up it works as expected.
ssh USER@ REMOTE_HOSTNAME mysqldump -v -u USER -pPASSWORD -h HOST --opt --compress DATABASE_NAME > db.sqlAny idea’s what’s causing this hang up?
Thanks
Add a Comment
Related Entries
- MySQL on OS X Reinstall Reminders
- Ruby on Rails Snippet for Changing Relative Paths to Absolute
- How To Install MacPorts, Apache2, Rails, MySql, Mongrel, and Subversion on an Intel Mac
- Rails Cheap, MySQL Expensive
- Leopard Installs Not Always Problem Free