Solved

Mysql - Copying Info to another database??

Posted on 2006-06-20
3
244 Views
Last Modified: 2008-03-10
Hi

I have got a scheduled task in place that moves information from 1 database (Firebird) to another (MySQL). The issue that i have, is that some information that goes into the MySQL database, also needs to be in ANOTEHR MySQL database, which is stored on the same server.

Rather than modifying the scheduled task to do 2 updates, is it possible to create a trigger, that would move selected data into the other database.

E.g. If account = "041" then copy field A, B, C, D into the other database

Is this possible?

Thanks very much

PS - high point score as it would be very valuable to me
0
Comment
Question by:seancurt
  • 2
3 Comments
 
LVL 30

Expert Comment

by:todd_farmer
ID: 16943913
Yes, it is absolutely possible, as long as the server is MySQL 5.0 and the databases are hosted by the same MySQL server instance.
0
 

Author Comment

by:seancurt
ID: 16948985
Hi

That sounds great, but how?
0
 
LVL 30

Accepted Solution

by:
todd_farmer earned 500 total points
ID: 16952666
The script below gives you an idea on how to start.  You will need another trigger for capturing UPDATE events and another for DELETE events, if appropriate:

create database db1;
create database db2;
use db1;
create table test (id int unsigned not null auto_increment primary key, name varchar(15), created timestamp);
use db2;
create table test_target(id int unsigned not null primary key, name varchar(15), friend varchar(15));
use db1;
delimiter ||
create trigger test_ins after insert on test
for each row begin
insert into db2.test_target (id, name) values (new.id, new.name);
end;
||
delimiter ;
insert into test (name) values ('Todd');
select * from db2.test_target;

0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question