Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

stored procedures - MySQL UDF sys_exec() doesn't work

I have a trigger which calls a stored procedure with parameters which calls SET result = sys_exec(cmd);. But it gives the error "function sys_exec does not exist".

I don't know what to do, on Tuesday I have presentation and because of this code line my project won't work. The codes which I try to work.

DELIMITER $$
CREATE PROCEDURE push_message
(p1   int,
 p2   int,
 p3 varchar(20))
BEGIN
 DECLARE cmd CHAR(255);
 DECLARE result CHAR(255);
 SET cmd = CONCAT('curl https://pubsub.pubnub.com/publish/demo/demo/0/mysql_triggers/0/%22',p1, ',' ,p2, ',' ,p3,'%22');
 SET result = sys_exec(cmd);
END$$; 


CREATE TRIGGER push_message_trigger AFTER INSERT ON your_table_name_here
FOR EACH ROW
CALL push_message(NEW.id, NEW.num, NEW.name);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try:

mysql> SELECT VERSION();
+-----------------+
| VERSION()       |
+-----------------+
| 5.5.35-1ubuntu1 |
+-----------------+
1 row in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'plugin_dir';
+---------------+------------------------+
| Variable_name | Value                  |
+---------------+------------------------+
| plugin_dir    | /usr/lib/mysql/plugin/ | -- copy 'lib_mysqludf_sys.so' here
+---------------+------------------------+
1 row in set (0.01 sec)

mysql> DROP FUNCTION IF EXISTS lib_mysqludf_sys_info;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> DROP FUNCTION IF EXISTS sys_get;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> DROP FUNCTION IF EXISTS sys_set;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> DROP FUNCTION IF EXISTS sys_exec;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> DROP FUNCTION IF EXISTS sys_eval;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> CREATE FUNCTION lib_mysqludf_sys_info RETURNS string SONAME 'lib_mysqludf_sys.so';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE FUNCTION sys_get RETURNS string SONAME 'lib_mysqludf_sys.so';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE FUNCTION sys_set RETURNS int SONAME 'lib_mysqludf_sys.so';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE FUNCTION sys_exec RETURNS int SONAME 'lib_mysqludf_sys.so';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE FUNCTION sys_eval RETURNS string SONAME 'lib_mysqludf_sys.so';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT sys_exec('curl http://stackoverflow.com/');
+--------------------------------------------+
| sys_exec('curl http://stackoverflow.com/') |
+--------------------------------------------+
|                                          0 |
+--------------------------------------------+
1 row in set (0.12 sec)

For more details, visit: 24.3.2.5 Compiling and Installing User-Defined Functions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...