Run python script on Database event

后端 未结 2 1408
梦如初夏
梦如初夏 2020-12-30 11:39

I\'m running a python script that makes modifications in a specific database. I want to run a second script once there is a modification in my database (local server).

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 12:13

    Thanks for your answers, i found a solution here:

    http://crazytechthoughts.blogspot.fr/2011/12/call-external-program-from-mysql.html

    A Trigger must be defined to call an external function once the DB Table is modified:

    DELIMITER $
    CREATE TRIGGER Test_Trigger
    AFTER INSERT ON SFCRoutingTable
    FOR EACH ROW
    BEGIN
    DECLARE cmd CHAR(255);
    DECLARE result int(10);
    SET cmd = CONCAT('python /home/triggers.py');
    SET result = sys_exec(cmd);
    END;
    $
    DELIMITER ;
    

    Here, to call my python script, I use 'sys_exec' which is a UDF (User Defined Function). You can download the library from here: https://github.com/mysqludf/lib_mysqludf_sys

提交回复
热议问题