mardi 6 octobre 2015

MySQL trigger and procedure with sys_exec()

I'm attempting to fire a Laravel console PHP command to push every inserted row to my client UI, but the procedure doesn't seem to work after installing lib_mysqludf_sys libraries for sys_exec()/sys_eval() support.

Environment is the Laravel Homestead Vagrant VM. This is running Ubuntu 14.04.3 and MySQL 5.6.19-0ubuntu0.14.04.1. I also compiled and successfully installed the lib_mysqludf_sys libraries.

  • When using sys_exec(), I get returned exit code 32512 when running the procedure.
  • When using sys_eval(), I get no output in my debug_msg output when running the procedure.
  • Using the cmd echoed in debug_msg, it runs without issue manually on the CLI.
  • No MySQL error.log output

Does anyone know how to further troubleshoot this issue?

DELIMITER $$

DROP PROCEDURE IF EXISTS homestead.debug_msg$$
DROP PROCEDURE IF EXISTS homestead.sessionActivity$$

CREATE PROCEDURE homestead.debug_msg(enabled INTEGER, msg VARCHAR(255))
BEGIN
  IF enabled THEN BEGIN
    select concat("** ", msg) AS '** DEBUG:';
  END; END IF;
END $$

CREATE PROCEDURE homestead.sessionActivity(id BIGINT)
BEGIN
  IF id THEN BEGIN
   DECLARE cmd CHAR(255);
   DECLARE result CHAR(255);
   SET cmd = CONCAT('/usr/bin/php /home/vagrant/Code/Laravel/artisan session:push ', id);
   SET result = sys_eval(cmd);
   #####SET result = sys_exec(cmd);
   call debug_msg(TRUE,cmd);
   #####call debug_msg(TRUE,result);
  END; END IF;
END$$

DELIMITER ;

Here is running with debug_msg displaying the cmd variable:

mysql> CALL homestead.sessionActivity(74499);
+--------------------------------------------------------------+
| ** DEBUG:                                                    |
+--------------------------------------------------------------+
| ** php /home/vagrant/Code/Laravel/artisan session:push 74499 |
+--------------------------------------------------------------+
1 row in set (0.00 sec)

Which runs fine manually:

root@homestead:~# php /home/vagrant/Code/Laravel/artisan session:push 74499
string(259) "new line: some shit eol"
root@homestead:~#

Here is running with debug_message displaying the result variable, using sys_exec(), but again, the PHP command is not ran, and no other output or logging shows errors (and sys_eval() instead of sys_exec() output here would be empty):

mysql> CALL homestead.sessionActivity(74499);
+-----------+
| ** DEBUG: |
+-----------+
| ** 32512  |
+-----------+
1 row in set (0.01 sec)

Curiously, while the lib_mysqludf_sys install creates functions, they don't show in show function status. I'm not sure if it's related.

mysql> CREATE FUNCTION lib_mysqludf_sys_info RETURNS string SONAME 'lib_mysqludf_sys.so';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE FUNCTION sys_get RETURNS string SONAME 'lib_mysqludf_sys.so';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE FUNCTION sys_set RETURNS int SONAME 'lib_mysqludf_sys.so';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE FUNCTION sys_exec RETURNS int SONAME 'lib_mysqludf_sys.so';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE FUNCTION sys_eval RETURNS string SONAME 'lib_mysqludf_sys.so';
Query OK, 0 rows affected (0.00 sec)

mysql> show function status;
Empty set (0.01 sec)

mysql> 



via Chebli Mohamed

1 commentaire:

Onpeaks a dit…

Laravel Development Company: ExpressTech Software Solutions offering Custom Laravel Development Services like Laravel RESTful API Development with Integration solution. +91-9806724185 or Contact@expresstechsoftwares.com

Enregistrer un commentaire