Solved

Mysql - Copying Info to another database??

Posted on 2006-06-20
3
243 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

Suggested Solutions

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). …
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 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