Download and Install lib_mysqludf_sys plugin
Go to URL https://github.com/mysqludf/lib_mysqludf_sys
Click on Download zip or use wget to download.
wget https://github.com/mysqludf/lib_mysqludf_sys/archive/master.zipExtract the downloaded plugin file and change directory to extracted directory.
unzip master.zipcd lib_mysqludf_sys-master/
Compile module with command below.
gcc -m64 -fPIC -Wall -I/usr/include/mysql -I. \
-shared lib_mysqludf_sys.c -o /usr/lib64/mysql/plugin/lib_mysqludf_sys.so
Login to mysql and create function sys_exec and sys_eval on required database.
mysql -u root -p
use test;
CREATE FUNCTION sys_exec RETURNS int SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_eval RETURNS int SONAME 'lib_mysqludf_sys.so';
Now for testing purpose we will create trigger that will execute after insert on each row of table tab_trig_test. First create table tab_trig_test.
use test;
create table tab_trig_test(
sn int,
name varchar(100)
);
Drop and create trigger that will execute after insert for each row on table tab_trig_test.
drop trigger if exists trig_test;
DELIMITER @@CREATE TRIGGER trig_test
AFTER INSERT ON tab_trig_test
FOR EACH ROW
BEGIN
DECLARE cmd CHAR(255);
DECLARE result int;
SET cmd=CONCAT('echo ', new.name, ' > /tmp/haha',new.name);
SET result = sys_exec(cmd);
END;
@@
DELIMITER ;
Thanks for sharing this, Dilli.
ReplyDelete-Prasanna.
My Pleasure. Thanks for the comment.
ReplyDelete-Dilli R. Maharjan
it is not working for me
ReplyDeletewhen i am writing \! cat /tmp/haharajiv this command it shows no such file or directory.
if you have any solution for that please let me know ASAP
DeleteHi Jaydeep, thank you for pointing out the error. Can you try \! cat /tmp/haha only. I am sure that should work
- Dilli
ReplyDeleteDELIMITER $$
CREATE PROCEDURE `callphp`()
BEGIN
declare cmd char(55);
declare result char(100);
SET cmd = CONCAT('sh /home/sudhir/Desktop/runphp.sh');
SET result = sys_exec(cmd);
END $$
DELIMITER ;
this is my code i dono whats wrong with this it never executes the .sh file any solution
showing error ERROR 1305 (42000) : FUNCTION test.sys_exec does not exist
ReplyDelete