MySQL Forums
Forum List  »  Triggers

Re: Triggers and mysql replication
Posted by: oussama hammami
Date: April 05, 2011 08:29AM

Actions carried out through triggers on a master are not replicated to a slave server so you need create the triggers on the slave.

BUT !
You can have the action of requests made by triggers in the binary log with federated tables (MySQL5) by adding the same table with a local connection.

-- Example:
-- We want install a replication of the table test_table that will be managed by Trg_Update triggers.

Create database TEST;
CREATE TABLE test_trigger (
id INT(20) NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL DEFAULT '',
PRIMARY KEY (id),
INDEX name (name),
) ;


CREATE TABLE test_table (
id INT(20) NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL DEFAULT '',
other VARCHAR(32) NOT NULL DEFAULT '',
PRIMARY KEY (id),
INDEX name (name),
INDEX other_key (other)
) ;


CREATE TABLE federated_table (
id INT(20) NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL DEFAULT '',
other VARCHAR(32) NOT NULL DEFAULT '',
PRIMARY KEY (id),
INDEX name (name),
INDEX other_key (other)
)
ENGINE=FEDERATED
CONNECTION='mysql://root@localhost/TEST /test_table';


DELIMITER |
CREATE TRIGGER Trg_Update AFTER INSERT ON test_trigger
FOR EACH ROW BEGIN
INSERT INTO federated_table (name, other) values (NEW.name, ‘test trigger on federated table -> OK’)
END|
DELIMITER ;

Options: Reply• Quote


Subject
Views
Written By
Posted
4060
March 12, 2011 03:29AM
1878
March 14, 2011 01:44AM
2195
March 18, 2011 12:50AM
Re: Triggers and mysql replication
2901
April 05, 2011 08:29AM
1620
April 05, 2011 09:10AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.