| Hi All, | | I have 2 separate mysql servers and need to import data from a table on | sever1 to | a table on server2. This would need to be done in Perl. | | The script in question already has open handles to both servers, so I | know I can | select all the rows from server1 and process them one by one and insert | into the table on server2, but I was wondering if there was a more | simple way to do this which would allow me to transfer the data from one | database handle directly to another? | | Looking on google, the closest example I can find is something like : | | #!/usr/bin/perl | use DBI; | | $dbh1=.....; | $dbh2=.....; | ... | | $statement = "select a,b,c,d,... from table1 where condition='$value'"; | $sth=$dbh1->prepare($sql); | my @results; | while (@results = $sth->fetchrow_array) { | | # build placeholders based on num of fields | my $placeholders; | $placeholders .= ($placeholders ? ",?" : "?") for (@results); | | my $sth2 = $dbh2->prepare("INSERT INTO table2 values | ($placeholders);"); | $sth2->execute(@results); | $sth2->finish; | } | | $sth1->finish; | $dbh1->disconnect(); | $dbh2->disconnect(); | | George Law | [EMAIL PROTECTED] | MSN: [EMAIL PROTECTED] | Phone: 864-678-3161
George, Did you try to "INSERT INTO db2.tablename SELECT fields from db1.tablename where field='Somevalue'" across different servers? Don't know if it's possible but it would certainly be more efficient. David -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]