My (SQL) WorkLog: MySQL - Copying records from remote server DB table to local server DB table

Wednesday, June 17, 2009

MySQL - Copying records from remote server DB table to local server DB table

Sometime you may need to populate(sync) local testing table with the production table which is hosted on a remote server.


# This command should be run on local server(SINGLE COMMAND)


mysqldump -t -h [remote_host_ip] -u[remote_User] -p[remote_Password] [remote_DbName] [remote_TableName] | mysql -h localhost -u [local_User] -p[local_Password] [local_DbName]



What if you want to copy last month data only?

mysqldump -t -h [remote_host_ip] -u[remote_User] -p[remote_Password] [remote_DbName] [remote_TableName] -w "column_date_time > NOW() - INTERVAL 1 MONTH"| mysql -h localhost -u [local_User] -p[local_Password] [local_DbName]

No comments:

Post a Comment