I want to insert rows from a specific table in a database to another database with a bash script. The two databases are on different servers. How can I do that?
I want something like this:
INSERT INTO db1.table1(row1, row2) SELECT row1,row2 FROM db2.table2;
But the databases are on different servers.
Thank you.
I think you need to use
sshto execute a remote command andmysldumpto get the rows from the remote db and mysql to insert the row to the local db.ssh <remoteuser>@<remoteServer> mysqldump -t -u <remoteDbUser> -p<remoteDbPass> <remoteDbName> <remoteDbTable> -w<whereCondition> | mysql -u <localDbUser> -p<localDbPass> <localDbName>Pay attenction that:
Use the man page for more information about the mysqldump command.