1
votes

I was set lib_mysqludf_sys.dll library in;

C:\Program Files\MySQL\MySQL Server 5.7\lib\plugin

And I was created this mysql function;

CREATE FUNCTION sys_exec RETURNS int SONAME 'lib_mysqludf_sys.dll';

It's created successful and not throw any exception.

Then I wrote this trigger on mysql;

CREATE DEFINER = CURRENT_USER TRIGGER `bb`.`mytable_AFTER_INSERT` AFTER INSERT ON `mytable` FOR EACH ROW
BEGIN
Call new_procedure();
END

And procedure like this;

CREATE DEFINER=`root`@`localhost` PROCEDURE `new_procedure`()
BEGIN 
    DECLARE cmd CHAR(255); 
    DECLARE result CHAR(255); 
    SET result = sys_exec('curl http://localhost:9095/Laputa');
    INSERT INTO trggr VALUES(result);
END

But sys_exec function return 1 and not connect to url.

How can I connect any websocket from procedure.

My system: windows10 64bit, MySql Server 5.7 'version_compile_machine':'x86_64','version_compile_os':'Win64'

I wrote this by looking at them:

https://support.pubnub.com/support/solutions/articles/14000043795-can-i-publish-a-message-via-a-database-trigger-

MySQL UDF sys_exec() doesn't work

Real time updates from database using JSF/Java EE

Thanks.

1

1 Answers

0
votes

curl is not a windows native command, you must download the binaries from curl page and copy the binaries (.exe and .dll) into your c:\windows directory... also you can use the full path of curl.exe

After that you can execute the command but sys_exec will return only 0 (success) or 1 (fail), to get the output of command you must use the sys_eval function:

CREATE FUNCTION sys_eval RETURNS int SONAME 'lib_mysqludf_sys.dll';