Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm trying to install lib_mysqludf_sys.so in mysql to create sys_exec function which will run an external java programm ..

first of all i issued this command :

CREATE FUNCTION sys_exec RETURNS INT SONAME 'lib_mysqludf_sys.so';

and i got this error :

ERROR 1126 (HY000): Can't open shared library 'lib_mysqludf_sys.so' (errno: 0 /usr/lib/mysql/plugin/lib_mysqludf_sys.so: wrong ELF class: ELFCLASS32)

this error is due to the 64 bit os...

i'm using 64 bit Ubuntu and this library file is of 32 bit.

I'm not getting the library of 64 bit..

I have gone trough this :

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

this is also giving error that file not present ..how should i resolve this

share|improve this question
    
"that file not present" -- what file? Can you be more specific? –  Michael - sqlbot Apr 11 '13 at 23:55
    
gcc -Wall -m64 -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o /usr/lib/lib_mysqludf_sys.so -fPIC gcc: error: lib_mysqludf_sys.c: No such file or directory gcc: fatal error: no input files compilation terminated. –  user21546 Apr 12 '13 at 7:06
add comment

1 Answer

You didn't say, in your question what the "file not present" message was, but I'm guessing it's this:

ERROR 1126 (HY000) at line 29: Can't open shared library 'lib_mysqludf_sys.so' 
(errno: 0 /usr/local/mysql/lib/plugin/lib_mysqludf_sys.so: cannot open shared 
object file: No such file or directory)
ERROR: unable to install the UDF

That makes sense, because you're telling gcc to write the file to /usr/lib/lib_mysqludf_sys.so... that's the -o option in your command line. Give gcc the path MySQL is expecting and the rest of the installation should work.

gcc -m64 -fPIC -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c \ 
-o /usr/local/mysql/lib/plugin/lib_mysqludf_sys.so \
-L/usr/lib/x86_64-linux-gnu/libstdc++.so.6

Also, whatever you're planning to do with this... don't say I didn't recommend against it. You're introducing both a potential security vulnerability and potentional performance and stability liability if these tools are deployed. This is not because there's anything wrong with the utility, but because of the amount of somewhat unorthodox functionality it opens up.

It's pretty cool, I admit. The lib_mysqludf_sys group of user-defined functions allow some interesting but easily-misappropriated capabilities, letting you spawn system commands and get either their generated output with sys_eval() or their return value with sys_exec() but really, I tend to suspect there's a reason why MySQL doesn't have these capabilities built in.

mysql> select sys_eval('df -k | grep xvda | tr -d "\n"') as cool_function_but_bad_idea;
+-----------------------------------------------------+
| cool_function_but_bad_idea                          |
+-----------------------------------------------------+
| /dev/xvda1       8256952   1216636   6620888  16% / |
+-----------------------------------------------------+
1 row in set (0.81 sec)

mysql> select sys_exec('/bin/false'), sys_exec('/bin/true');
+------------------------+-----------------------+
| sys_exec('/bin/false') | sys_exec('/bin/true') |
+------------------------+-----------------------+
|                    256 |                     0 |
+------------------------+-----------------------+
1 row in set (1.59 sec)

Update to address this error message:

gcc -Wall -m64 -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o 
/usr/lib/lib_mysqludf_sys.so -fPIC gcc: error: lib_mysqludf_sys.c: No such 
file or directory gcc: fatal error: no input files compilation terminated

The statement in question is directing "gcc" to compile a 64-bit version from the source code, which is found in lib_mysqludf_sys.c. This is one of the files you downloaded, so, to compile it, you need to be inside the directory where you downloaded the lib_mysqludf_sys files. This error suggests that you aren't. The download package isn't limited to 32 bit, it's just that it only builds a 32 bit version unless you use the gcc -m64 -fPIC ... statement.

share|improve this answer
    
ok u mean...i need to download this lib_mysqludf_sys.c file ...can you please elaborate this more simply..in a step by step form..so that other can also find it useful..coz no better and easy solution has been provided over the net –  user21546 Apr 14 '13 at 16:02
    
You apparently have downloaded a copy of the 32-bit version of lib_mysqludf_sys.so -- right? Trying to install that on a 64-bit MySQL Server is why you got the ELFCLASS32 error... so, where and how did you get that file? In the same place, you should see the source file lib_mysqludf_sys.c which you compile with gcc using the command we've been referencing. –  Michael - sqlbot Apr 16 '13 at 1:19
    
i had placed this lib_mysqludf_sys.c in /usr/lib/mysql/plugin and in same place lib_mysqludf_sys.so resides.. im unable to configure /usr/include/mysql yet ..there is no folder in this path... –  user21546 Apr 16 '13 at 7:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.