Search code examples
mysqldatabase-designsshpercona

creating a trigger that executes sql statement over ssh in mysql


I have 2 (th and ct) servers that are completely separated each with it's own database I want to sync a table(et) in th with ct I want if new inserts are done in table th a trigger will fire a ssh connection to ct server and insert the new rows I think the script should look something like the following but I can't figure out the syntax

 DROP TRIGGER IF EXISTS et-sync
CREATE TRIGGER et-sync AFTER INSERT ON th.et
FOR EACH ROW BEGIN
 ssh user@11.11.2.11 "mysql -uroot -ppassword -e \"INSERT  db_testplus.user SET t = NEW.t;""
END;

and should I use this or just use Percona Toolkit for MySQL (pt-table-sync) as I don't think adding a tool to control database sync at that scale is worth it(added complexity)

I know that adding replicas is properly the best solution but considering the current system design I thought of postponing the redesign of ct database for some time as it will take sometime to make it from scratch and it's an important part for the business

any suggestions ??


Solution

  • For security reasons, MySQL does not allow launching processes from within itself.

    Usually the alternative is to make a cron job to do orchestrate the actions, reaching into the database as needed to communicate and coordinate.