MYSQL
HOME > DB > MYSQL
2018.09.30 / 22:42

[MySQL,MariaDB] lib_mysqludf_sys - User-defined functio 설치 방법

GAScripter
추천 수 9

https://mariadb.com/kb/en/mariadb/create-function-udf/


https://github.com/mysqludf/lib_mysqludf_sys




gcc -m64 -fPIC -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o /usr/local/mysql/lib/plugin/lib_mysqludf_sys.so



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';



MariaDB [(none)]> select * from mysql.func;

+-----------------------+-----+---------------------+----------+

| name                  | ret | dl                  | type     |

+-----------------------+-----+---------------------+----------+

| lib_mysqludf_sys_info |   0 | lib_mysqludf_sys.so | function |

| sys_get               |   0 | lib_mysqludf_sys.so | function |

| sys_set               |   2 | lib_mysqludf_sys.so | function |

| sys_exec              |   2 | lib_mysqludf_sys.so | function |

| sys_eval              |   0 | lib_mysqludf_sys.so | function |

+-----------------------+-----+---------------------+----------+

5 rows in set (0.00 sec)




MariaDB [(none)]> select sys_exec('/bin/false'), sys_exec('/bin/true');

+------------------------+-----------------------+

| sys_exec('/bin/false') | sys_exec('/bin/true') |

+------------------------+-----------------------+

|                    256 |                     0 |

+------------------------+-----------------------+

1 row in set (0.01 sec)



MariaDB [(none)]> select sys_eval('df -h')\G;

*************************** 1. row ***************************

sys_eval('df -h'): Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/vg_rnd07-lv_root

                       50G   40G  9.5G  81% /

tmpfs                  32G   15G   17G  48% /dev/shm

/dev/sda1             485M   91M  369M  20% /boot

/dev/mapper/vg_rnd07-lv_home

                       99G   65G   29G  70% /home

/dev/mapper/vg_rnd07-lv_DBMS

                      296G  202G   79G  72% /DBMS

//172.16.150.50/STORAGE

                      3.7T  596G  3.1T  16% /STORAGE


1 row in set (0.01 sec)


ERROR: No query specified