MYSQL
HOME > DB > MYSQL
2018.09.30 / 22:39

Ubuntu + MySQL Ŀǵ

GAScripter
õ 6

16.04 + MySQL Ư Ͱ Էµ Ŀǵ带 Ȳ . 
丮 ̷ ȼ lib_mysqludf_sys ǽðڴ. 


ũ: https://github.com/mysqludf/lib_mysqludf_sys 


MySQL ÷ θ Ȯ. 


mysql> show variables like 'plugin_dir';


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

| Variable_name | Value                  |

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

| plugin_dir    | /usr/lib/mysql/plugin/ |

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




UDF ҽ ް.  


$ git clone https://github.com/mysqludf/lib_mysqludf_sys.git

$ cd lib_mysqludf_sys/



Ե Makefile ׽Ʈ. -fPIC ֶ ״ . 

$ sudo apt-get install libmysqlclient-dev
$ gcc -Wall -I/usr/include/mysql -I. -fPIC  -shared lib_mysqludf_sys.c -o lib_mysqludf_sys.so


Ȯ , Makefile . 

Makefile 

LIBDIR=/usr/lib/mysql/plugin

install:
        gcc -Wall -I/usr/include/mysql -I. -fPIC -shared lib_mysqludf_sys.c -o $(LIBDIR)/lib_mysqludf_sys.so



ġ


$ sudo ./install.sh



MySQL ׽Ʈ. 


mysql> select sys_exec('touch /tmp/test_mysql') ;

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

| sys_exec('touch /tmp/test_mysql') |

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

|                             32512 |

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

1 row in set (0.01 sec)



sys() Լ ϴµ 31512 ...  Ǵ ϳ . 


۲ ޴ apparmor UDF ´ٴ Ź ֽ. 

https://www.cyberciti.biz/faq/ubuntu-linux-howto-disable-apparmor-commands/



apparmor ¸ Ȯ. 


$ sudo apparmor_status


apparmor module is loaded.

16 profiles are loaded.

16 profiles are in enforce mode.

......

   /usr/sbin/mysqld

...



mysqld 󿡼


$ sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/

$ sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld


# ٽ Ȯ

# sudo apparmor_status



apparmor mysql 籸


$ sudo /etc/init.d/mysql restart

$ sudo /etc/init.d/apparmor restart



MySQL sys_exe() õ


mysql> select sys_exec('touch /tmp/test_mysql');

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

| sys_exec('touch /tmp/test_mysql') |

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

|                                 0 |

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

1 row in set (0.01 sec)



/tmp Ȯ. 


$ ll /tmp

total ...

drwxrwxrwt 13 root    root    4096 Aug 20 22:38 ./

drwxr-xr-x 24 root    root    4096 Jul  6 14:40 ../

-rw-r-----  1 mysql   mysql      0 Aug 20 22:38 test_mysql

......



Ʈſ ܺ ų ִ.



ũ

https://github.com/mysqludf/lib_mysqludf_sys

http://bernardodamele.blogspot.com/2009/01/command-execution-with-mysql-udf.html

https://www.cyberciti.biz/faq/ubuntu-linux-howto-disable-apparmor-commands/