title: Call python script from mysql trigger
body: <p>I read <a href="http://crazytechthoughts.blogspot.sg/2011/12/call-external-program-from-mysql.html" rel="nofollow">http://crazytechthoughts.blogspot.sg/2011/12/call-external-program-from-mysql.html</a> and install <a href="https://github.com/mysqludf/lib_mysqludf_sys#readme" rel="nofollow">lib_mysqludf_sys</a></p>
  
  <p>And try to call python script inside mysql trigger.</p>
  
  <p>Here is my test trigger:</p>
  
  <pre><code>DROP TRIGGER IF EXISTS ljj_rigger;
  
  CREATE TRIGGER ljj_rigger 
  AFTER INSERT ON test_trigger 
  FOR EACH ROW 
  BEGIN
          DECLARE cmd1 CHAR(255);
          DECLARE cmd2 CHAR(255);
          DECLARE cmd3 CHAR(255);
          DECLARE result1 int(10);
          DECLARE result2 int(10);
          DECLARE result3 int(10);
          SET cmd1 = 'python /home/jaskey1103/python/test.py';
          SET cmd2 = 'touch /home/jaskey1103/python/bybash';
          SET cmd3 = '/home/jaskey1103/python/callpy.sh';
  
          SET result1 = sys_exec(cmd1);
          SET result2 = sys_exec(cmd2);
          SET result3 = sys_exec(cmd3);
  
          insert into test_trigger_copy(value) values(result1);
          insert into test_trigger_copy(value) values(result2);
          insert into test_trigger_copy(value) values(result3);
  END;
  
  
  commit;
  </code></pre>
  
  <p>But when the trigger runs, I could find new file <code>bytouch</code> but can't find new file created by python script. </p>
  
  <p>And for testing, the inserted result into copy table are: 0,0,512. </p>
  
  <p>test.py:</p>
  
  <pre><code>import os
  
  def touch(fname, times=None):
      fhandle = open(fname, 'a')
      try:
          os.utime(fname, times)
      finally:
          fhandle.close()
  
  print 'creating file'
  touch("bypython")        
  </code></pre>
  
  <p>callpy.sh:</p>
  
  <pre><code>python test.py
  </code></pre>