« Move production SRC Interviewer site to dev | Main

November 01, 2013

Copy and import a mySQL database

This is the original source.

Createa backup of the database:
$ mysqldump --opt -u [user] -p [db] -h [host] > [filename].sql
- If dropped -h default to localhost.

Create backup with compression:
$ mysqldump --opt -u [user] -p [db] -h [host] | gzip > [filename].sql.gz

Dump and import:
$ mysqldump --opt -u [user] -p [db] -h [host] | mysql -u [user] -p -h [host] [db]
- The first part dumps database 1 and the second part imports the dump into database 2.

This appears to work on ITS servers:
% mysqldump --opt -u isrdco -p[password] isrdco --host=webapps-db.web.itd | mysql -u isrdcodv -p --host=webapps2-db.miserver.it.umich.edu isrdcodv

Connect to mySQL via command line:

$ mysql -u [dbuser] -h [dbhost] -p


Import a database:

$ mysql -u [dbuser] -p -h [dbhost] [dbname] < [db_toimport.sql]

SFTP into a machine through a non-standard port

$ sftp -oPort=[port] [username]@[host]

Posted by kkwaiser at November 1, 2013 04:37 PM


Login to leave a comment. Create a new account.