Bug #62449 MySQL cannot refer the secondary dll of a UDF dll in plugin_dir (my.ini)
Submitted: 16 Sep 2011 10:04 Modified: 30 Dec 2011 18:35
Reporter: Do-jeon Kim Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: User-defined functions ( UDF ) Severity:S3 (Non-critical)
Version:5.5.14-log OS:Microsoft Windows (XP)
Assigned to: CPU Architecture:Any
Tags: lib_mysqludf_preg.dll, libpcre.dll, plugin_dir, udf

[16 Sep 2011 10:04] Do-jeon Kim
Description:
MySQL cannot refer the secondary dll of a UDF dll, both of which are located in plugin_dir (my.ini).

To use regular expression in MySQL, I downloaded two dll files at
http://www.mysqludf.org/lib_mysqludf_preg/ .

One is lib_mysqludf_preg.dll, and another is libpcre.dll.

Following the instruction for windows binaries in that page, 
I set plugin_dir "C:\..."(omitted) in my.ini,
and put both files at that folder.

When I've tried to install the UDF, I only received this error.

SQL Error (1126): Can't open shared library 'lib_mysqludf_preg.dll' (errno: 0 )
or
SQL Error (1126): Can't open shared library 'lib_mysqludf_preg.dll' (errno: 2 )

I solved it as follows.

First, I leave lib_mysqludf_preg.dll at plugin_dir,
and move libpcre.dll to {MySQL Server}\bin.

Then, I executed "CREATE FUNCTION ...",
it worked successfully.

How to repeat:
-- --------------------
-- Step 1. Add this at [mysqld] section of my.ini
-- --------------------

plugin_dir = "C:/Program Files/MySQL/MySQL Server 5.5/lib/plugin"

-- --------------------
-- Step 2. Download a zip file, and unzip it to the plugin_dir.
-- --------------------

http://www.mysqludf.org/lib_mysqludf_preg/lib_mysqludf_preg-1.0-bin.zip
-- This two files shall be decompressed.
-- lib_mysqludf_preg.dll
-- libpcre.dll

-- --------------------
-- Step 3. Restart server.
-- --------------------

-- --------------------
-- Step 4. Execute this.
-- --------------------

CREATE FUNCTION preg_capture RETURNS STRING SONAME 'lib_mysqludf_preg.dll';
-- You will met this message.
-- SQL Error (1126): Can't open shared library 'lib_mysqludf_preg.dll' (errno: 0 )

-- --------------------
-- Step 6. Move libpcre.dll from plugin_dir to bin folder.
-- --------------------

-- FROM: C:/Program Files/MySQL/MySQL Server 5.5/lib/plugin
-- TO: C:\Program Files\MySQL\MySQL Server 5.5\bin

-- --------------------
-- Step 7. Execute this.
-- --------------------

CREATE FUNCTION preg_capture RETURNS STRING SONAME 'lib_mysqludf_preg.dll';
-- This works well.

Suggested fix:
Is it desirable that secondary dll be located with main dll at the same folder of plugin_dir?

Thanks.
[16 Sep 2011 12:57] Valeriy Kravchuk
I think that your plugin_dir is NOT listed in PATH environment variable at OS level. While server searches for libraries implementing UDFs in plugin_dir, if this library depends on some other library usual procedure to find DLL applies, that is, PATH is used or, on Windows, current directory for the mysqld.exe binary (bin subdirectory of server distribution in your case). 

I think you can put that other library in any directory that is listed in PATH.
[19 Sep 2011 5:13] Do-jeon Kim
Yes, you're right.

When I moved libpcre.dll file to the folder which written in 'path' configuration such like "C:\Windows\system32", it worked successfully.

Thanks.
[19 Sep 2011 6:50] Valeriy Kravchuk
So, I'd say this is not a bug. Just depends on where OS is looking for DLLs. Do you agree?
[28 Sep 2011 2:04] Do-jeon Kim
Sorry for late response.

Yes. I agree this is exactly not a bug.

I think it's due to the wrong description at http://www.mysqludf.org/lib_mysqludf_preg

Maybe this report will be an answer for
http://forums.mysql.com/read.php?11,398045

Thanks for your advise.
[30 Dec 2011 18:35] Valeriy Kravchuk
Looks like this problem was not a result of any bug in MySQL code.