1

I need to call an external script from a trigger to intercept every insert in the DB. This because I can't poll for that value, I'm coding for an embedded system with ARM architecture and only 250MB of RAM. Trigger is the right options, and the code of the trigger works well, I get:

FUNCTION mydb.sys_exec does not exist (MySQL error code: 1305, SQLState: 42000 )

so I tried to install this: https://github.com/mysqludf/lib_mysqludf_sys

but it gets me:

ERROR: You need libmysqlclient development software installed 
to be able to compile this UDF, on Debian/Ubuntu just run:
apt-get install libmysqlclient15-dev

so if I type

sudo apt-get install libmysqlclient15-dev

I get: Note, selecting 'libmysqlclient-dev' instead of 'libmysqlclient15-dev'

and of course it is not the right package because it doesn't work. The .so file contained in the git is compiled for intelx86.

Anyone has an idea? Compiling the .c in the git it's quite impossible due the lot of missing dependencies.

Or.. how can I execute an external script from a trigger without sys_exec?

PS: for completeness, this is the trigger script:

DELIMITER @@

CREATE TRIGGER command_controller
AFTER INSERT ON myDB.foo
FOR EACH ROW
BEGIN
 DECLARE cmd CHAR(255);
 DECLARE result int(10);
 SET cmd='./foo ';
 SET result = sys_eval(cmd);
END;
@@
DELIMITER ;
1
  • sudo apt install libmysqlclient-dev worked for me. Commented Jul 10, 2018 at 21:38

1 Answer 1

3

Here's a minimal version that works for me:

#include <string.h>
#include <stdlib.h>
#include <mysql.h>

my_bool sys_exec_init(
  UDF_INIT *initid
, UDF_ARGS *args
, char *message
){
  unsigned int i=0;
  if(args->arg_count == 1
  && args->arg_type[i]==STRING_RESULT){
    return 0;
  } else {
    strcpy(
      message
    , "Expected exactly one string type parameter"
    );
    return 1;
  }
}
void sys_exec_deinit(
  UDF_INIT *initid
){
}
my_ulonglong sys_exec(
  UDF_INIT *initid
, UDF_ARGS *args
, char *is_null
, char *error
){
  return system(args->args[0]);
}

I compile it with this line:

gcc -Wall -I include -I /home/rbouman/mysql/mysql-5.6.10-linux-glibc2.5-x86_64/include -shared -fPIC -o sys_exec.so sys_exec.c
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.