MySQL UDF sys_exec()不起作用

时间:2014-12-21 06:50:12

标签: mysql stored-procedures user-defined-functions

我有一个触发器,它使用调用SET result = sys_exec(cmd);的参数调用存储过程。但它给出了错误“函数sys_exec不存在”。

我不知道该怎么做,周二我有演示文稿,因为这个代码行我的项目不起作用。 我努力工作的代码。

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);

3 个答案:

答案 0 :(得分:6)

尝试:

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)

有关详细信息,请访问:24.3.2.5 Compiling and Installing User-Defined Functions

答案 1 :(得分:2)

尝试一次。

要遵循的步骤...

=>从https://github.com/mysqludf/lib_mysqludf_sys

获取文件

=>转到终端中的文件夹路径

=>执行:

gcc -DMYSQL_DYNAMIC_PLUGIN -fPIC -Wall -m64 -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o lib_mysqludf_sys.so

注意:如果32位操作系统在上述命令中将-m64替换为-m32。

=>在mysql shell中执行以下操作

SHOW VARIABLES LIKE 'plugin_dir';

成功输出的示例

+---------------+------------------------+ | Variable_name | Value | +---------------+------------------------+ | plugin_dir | /usr/lib/mysql/plugin/ | +---------------+------------------------+ =>将lib_mysqludf_sys.so文件复制到上述路径。

=>在mysql shell中执行以下操作

CREATE FUNCTION sys_exec RETURNS INT SONAME 'lib_mysqludf_sys.so';

答案 2 :(得分:0)

如果您的操作系统是Windows,请使用此文件(对于Linux,有.so文件;对于Windows,有.dll文件) https://github.com/rapid7/metasploit-framework/tree/master/data/exploits/mysql

下载文件并复制到您的../MySQL/lib或../MySQL/lib/plugin目录中。

打开MySQL,复制并执行:

DROP FUNCTION IF EXISTS lib_mysqludf_sys_info;
DROP FUNCTION IF EXISTS sys_get;
DROP FUNCTION IF EXISTS sys_set;
DROP FUNCTION IF EXISTS sys_exec;
DROP FUNCTION IF EXISTS sys_eval;

CREATE FUNCTION lib_mysqludf_sys_info RETURNS string SONAME 'lib_mysqludf_sys.dll';
CREATE FUNCTION sys_get RETURNS string SONAME 'lib_mysqludf_sys.dll';
CREATE FUNCTION sys_set RETURNS int SONAME 'lib_mysqludf_sys.dll';
CREATE FUNCTION sys_exec RETURNS int SONAME 'lib_mysqludf_sys.dll';
CREATE FUNCTION sys_eval RETURNS string SONAME 'lib_mysqludf_sys.dll';

然后您可以通过以下方式调用.exe文件:

DECLARE cmd CHAR(255);
DECLARE result int(10);
SET cmd = "../<ProjectApp>/bin/Debug/netcoreapp3.1/<appName>.exe";
SET result = sys_exec(cmd);