You could but only under 3 specific conditions:
The second table you are updating on another server is:
- a MyISAM table
- identically the same table structure as in the first server
- represented in MySQL in the first server as storage engine FEDERATED
First, make sure you have the FEDERATED engine enabled in MySQL
Just run SHOW ENGINES;
If the FEDERATED storage engine does not exist or is disabled, read no further.
Otherwise, you can try this out by writing it as an INSERT AFTER and an UPDATE AFTER trigger.
For this example:
- SERVER1 has database
this_db
with table this_table
- SERVER2 has database
that_db
with table that_table
- SERVER2 has IP address
10.20.30.250
Table structure looks like this:
CREATE TABLE `this _table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fruit` char(10) NOT NULL,
`number` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
First, make sure the table structures are MyISAM and identical...
On the first server, do SHOW CREATE TABLE this_db.this_table\G
On the other server, do SHOW CREATE TABLE that_db.that_table\G
On the first server, run this:
CREATE TABLE this_db.that_table LIKE this_db.this_table;
On the first server, run this:
ALTER TABLE this_db.that_table ENGINE=FEDERATED
CONNECTION='mysql://10.20.30.250/that_db/that_table';
On the first server, create an INSERT AFTER trigger against this_db.this_table
:
use this_db
DELIMITER $$
CREATE TRIGGER this_table afterinsert AFTER INSERT ON this_table
FOR EACH ROW
INSERT INTO that_table (id,fruit,number)
VALUES (NEW.id,NEW.fruit,NEW.number);
$$
DELIMITER ;
On the first server, create an UPDATE AFTER trigger against this_db.this_table
:
use this_db
DELIMITER $$
CREATE TRIGGER this_table afterupdate AFTER UPDATE ON this_table
FOR EACH ROW
UPDATE that_table SET fruit=NEW.fruit,number=NEW.number WHERE id=OLD.id;
$$
DELIMITER ;
That's it.
Give it a try!!!