call external script with mySQL trigger WHITOUT sys_exec on ubuntu ARMHF

匿名 (未验证) 提交于 2019-12-03 08:28:06

问题:

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:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!