1

Here is the code,

delimiter //
create procedure trig ()
begin
    declare cmd varchar(50);
    set cmd = "sh /home/yogaraj/Documents/Maastry/firefox.sh";
    system cmd;
end //

delimiter ;

But I can't execute system command. Can somebody help me?

RolandoMySQLDBA
  • 185,223
  • 33
  • 326
  • 536
Yogaraj
  • 121
  • 1
  • 1
  • 2

1 Answers1

3

This cannot be accomplished. Why ?

According to Can MySql stored proc call a system cmd? (from July 19, 2009 11:47AM)

This question is asked several times a week. The answers are (i) not out of the box, for very good reasons, (ii) you could write and link into your server a UDF which calls the operating system, but that would create a glaring security issue for your app.

For example, I have written about using system before : Why would I use the MySQL "system" command?. In my post, I showed how easy it would be to step into the operating system with

mysql> \! bash
[root@**** ~]# exit
exit
mysql>

Imagine what one could do in the OS because of such a breach.

Usually, stored procedures are used to prevent SQL injection. If system was allowed within a stored procedure, that eliminates such security.

You will have to run the script as follows

mysql> system /home/yogaraj/Documents/Maastry/firefox.sh

or

mysql> \! /home/yogaraj/Documents/Maastry/firefox.sh

This is all you can really do

RolandoMySQLDBA
  • 185,223
  • 33
  • 326
  • 536