When a new row is added to the database, you need to call an external command-line program

Is it possible for the MySQL database to call an external exe file when a new row is added to one of the tables in the database?

I need to track changes in the database, so when the changes occur, I need to do a few batch jobs outside the database.

+2
source share
4 answers

Chad Birch has a good idea using MySQL triggers and a custom function . You can find out more at the MySQL CREATE TRIGGER Syntax link .

, , ​​? , , MySQL . , , , . MySQL , . , Chad Birch , MySQL, .

, MySQL, , , INSERTED UPDATED: , say database_changes. , , .

, .

, , : database_changes date, table_name row_id, , :

CREATE TRIGGER `my_trigger`
AFTER INSERT ON `table_name`
FOR EACH ROW BEGIN
  INSERT INTO `database_changes` (`date`, `table_name`, `row_id`)
  VALUES (NOW(), "table_name", NEW.id)
END;

script - :

  • database_changes.
  • .
  • .
  • 1-3 , database_changes .

, , , ( , database_changes).

+13
  • , : " ". " ", " " mysqlbinlog. , .

+4
0

, - - , (, "", "" "," success ") - , " ".

It depends on how soon the batch job should complete. If this is something that needs to be started "sooner or later" and can fail and you need to try again, be sure to ask the application to poll the table and run them as necessary.

0
source

All Articles