Hey Chuck,

We replicate data on a regular basis from Oracle to MySQL and back using
perl cron scripts. Here's a basic one for ya:

#!/usr/bin/perl

use strict;
use DBI;

my $dbh1=DBI->connect("DBI:mysql:dbname:host.mark.com:6969", 'root'
,'password');
my $dbh2=DBI->connect("DBI:mysql:dbname2:host2.mark.com:6969", 'root'
,'password');

my $sth1 = $dbh1->prepare("select name, sex from members");
my $time = time();
my $sth2 = $dbh2->prepare("insert into members (name, sex, stamp) values (?,
?, $time)");

$sth1->execute();
my ($name, $sex);

while(($name, $sex) = $sth1->fetchrow())
{
        print "inserting $name\t$sex\n";
        $sth2->execute($name, $sex);
}
$sth1->finish();
$sth2->finish();
$dbh1->disconnect();
$dbh2->disconnect();
exit;
--cut--

I probably forgot something really silly because I haven't tested this at
all but I think that'll get ya started. You'll need perl5 with DBI
installed. Once you install DBI do a 
perldoc DBI 
and that will give you tons of info. Perl is definitelly the way to go if
you're sucking data from one DB, parsing and inserting into another.

Mark.


-----Original Message-----
From: Chuck Barnett [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 24, 2001 6:22 PM
To: Steve Ruby
Cc: [EMAIL PROTECTED]
Subject: Re: automation question: How do I copy the data from one table
to another table with a time stamp every night?


Thanks for replying.
I know the SQL commands, I want to know how to automate the whole sequence.

I've always written php pages that do the calls.  I want to write a script
to do it on the server as a cron job or something.

thanks
Chuck
----- Original Message -----
From: "Steve Ruby" <[EMAIL PROTECTED]>
To: "Chuck Barnett" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, January 24, 2001 12:34 PM
Subject: Re: automation question: How do I copy the data from one table to
another table with a time stamp every night?


> Chuck Barnett wrote:
> >
> > How do I copy the data from one table to another table with a time stamp
> > every night?
> >
> > example:  table A contains x,y,z.
> >
> > at midnight, I want to copy table A's contents to table B (B has same
> > fields, just adds a date field) and reset x,y,z to zero.
> >
>
>
> what do you mean by "reset to zero"  If you want to copy the files
> from A to B you can just do
>
> insert into B select x,y,z,now() from A;
> delete form a;
>
> if your date field in B is a TIMESTAMP type you can avoid the now()
> part and do
>
> inesrt into B (x,y,z) select x,y,z from A;
> delete from a;
>
> See the manual about the insert statement for more info.
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail
<[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to