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 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 ;
(I found this approach at http://crazytechthoughts.blogspot.com/2011/12/call-external-program-from-mysql.html.)