在使用编译出的lib_mysqludf_sys.so遇到了如下等等问题
1.
failed:FUNCTION ramsdb.sys_exec does not exist!
2.
ERROR 1126 (HY000): Can't open shared library 'lib_mysqludf_sys.so' (errno: 11/usr/lib64/mysql/plugin/lib_mysqludf_sys.so: wrong ELF class: ELFCLASS32)
完整安装udf调用系统程序具体步骤如下:
- 下载https://github.com/mysqludf/lib_mysqludf_sys#readme
- zip解压,然后复制到/opt目录下
- cd /opt ,编译so文件:
gcc -DMYSQL_DYNAMIC_PLUGIN -fPIC -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o lib_mysqludf_sys.so
4. 登录mysql, 执行sql>
SHOW VARIABLES LIKE 'plugin_dir';
5. 取得plugin_dir,即补丁目录:/usr/lib64/mysql/plugin/,将上一步编译得到的lib_mysqludf_sys.so拷贝至/usr/lib64/mysql/plugin/
6. 在/usr/lib64/mysql/plugin/目录下设置权限:
chmod 777 lib_mysqludf_sys.so
7.拷贝lib_mysqludf_sys.sql里边的sql语句,
DROP FUNCTION IF EXISTS lib_mysqludf_sys_info;
DROP FUNCTION IF EXISTS sys_get;
DROP FUNCTION IF EXISTS sys_set;
DROP FUNCTION IF EXISTS sys_exec;
DROP FUNCTION IF EXISTS sys_eval;
CREATE FUNCTION lib_mysqludf_sys_info RETURNS string SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_get RETURNS string SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_set RETURNS int SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_exec RETURNS int SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_eval RETURNS string SONAME 'lib_mysqludf_sys.so';
并在mysql执行所有sql语句
8.来个触发器测下:
DELIMITER $$
USE `testsb`$$
DROP TRIGGER /*!50032 IF EXISTS */ `t_working`$$
CREATE
/*!50017 DEFINER = 'root'@'%' */
TRIGGER `t_working` BEFORE UPDATE ON `t_tel`
FOR EACH ROW BEGIN
DECLARE done INT DEFAULT 0;
IF new.ACTIVE!=old.ACTIVE THEN
SET done = sys_exec("sh /home/working/test.sh");
UPDATE t_working SET working=new.ACTIVE WHERE id=new.wkID;
END IF;
END;
$$
DELIMITER ;
大功告成!