Solved

Mysql - Copying Info to another database??

Posted on 2006-06-20
3
241 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
Comment Utility
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
Comment Utility
Hi

That sounds great, but how?
0
 
LVL 30

Accepted Solution

by:
todd_farmer earned 500 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now