Ubuntu + MySQL ¿¡¼ ¼Ð Ä¿¸Çµå »ç¿ë
¿ìºÐÅõ 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/
ºôµå ¹× ¼³Ä¡
$ 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