本文介绍了从MySQL存储过程执行Shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用MySQL存储过程运行任意的Shell命令-例如,将文件从一个文件夹移动到另一个文件夹?如果可以,怎么办?
Is it possible to run arbitrary shell commands - for instance, to move a file from one folder to another - using a MySQL stored procedure? If so, how?
推荐答案
MySQL并没有立即提供此功能,而是由 lib_mysqludf_sys
库.如果安装了该程序,则可以调用其sys_exec
函数来执行命令:
MySQL doesn't provide this functionality out of the box, but it is provided by the lib_mysqludf_sys
library. If you install that, you will be able to call its sys_exec
function to execute commands:
DELIMITER @@
CREATE TRIGGER Test_Trigger
AFTER INSERT ON MyTable
FOR EACH ROW
BEGIN
DECLARE cmd CHAR(255);
DECLARE result int(10);
SET cmd=('mv path/to/file new/path/file');
SET result = sys_exec(cmd);
END;
@@
DELIMITER ;
(我在 http://crazytechthoughts.blogspot.com/2011/12/call-external-program-from-mysql.html .)
这篇关于从MySQL存储过程执行Shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!