简体   繁体   中英

will triggers run in MySQL slave in a Single Master Multi-Slave replication

Our customer is running a Single Master with multiple slaves(in a cluster).

Now, he wants us to write some triggers (only) that run on the slave(s) when new records are added, updated or deleted on the slave(s). This trigger should run an external java program.

Is this possible ? recommended ?

How do we run a java program from the trigger ? Is it recommended/safe ?

Any gotchas that need to be taken care of ?

Yes, it's possible. You need to create those triggers on slaves, they'll be triggered as binlog is read and executed.

You can execute an external program using sys_exec UDF available from MySQL Forge ( or this link ).

SELECT sys_exec('/path/to/program')

Just beware of what the program does, until the external program returns - query won't finish. If it's something that does further processing, I suggest creating some sort of a queueing system listening on a port so you can immediately exit(0) , let the program do its stuff and release mysql thread so the query can finish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM