Search code examples
mysqlmysql-workbenchmysql-error-1064

Mysql trigger functions - execute code in file


I'm experimenting triggers functions in mysql. I got error as You have a sql syntax error at line 3. The code which I used,

use maas;
create trigger dummy_trigger after insert on dummy
for each row begin
    declare cmd varchar(255);
    declare result integer(10);
    set cmd = concat('python /home/yogaraj/for_sql.py');
    set result = sys_exec(cmd);
end;

Error Output:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

Aim: I'm trying to execute a python file located in the home directory. I'm using mysql workbench.


Solution

  • If you use an SQL editor for this code then you have to specify a delimiter so that the inner commands of the create trigger code don't get parsed as individual statements.

    However you can use the trigger pane in the table editor to create a trigger without all the decoration:

    enter image description here

    The blue dot left in the gutter shows that your statement is perfectly ok.