Research on UDF-Can & amp; #39; t open shared library in MYSQL

Source: Internet
Author: User

Ninty s blog
Mysql supports UDF extension, so that we can call the functions in the DLL to implement some special functions.
However, the specific limitations of UDF vary with MYSQL versions. Record the following:

I heard that (I just heard that I didn't do a test), in versions earlier than MYSQL 4.1, I can register any function in all DLL files into MYSQL for MYSQL to call.
No matter where the DLL is, what the function declaration is.

In MYSQL 4.1 and later versions, UDF functions are restricted. Only functions that implement a specific interface can be successfully registered in MYSQL,
This prevents unauthorized calling of system DLL through MYSQL.

After MYSQL5, there are restrictions on the location of the registered DLL. When creating a function, the corresponding DLL cannot contain/or. Simply put, it cannot be an absolute path.
So we release the DLL to the system32 directory to skip this restriction .. Or put it in the root directory of the drive letter and skip the restriction using the c: udf. dll format.

After a reminder from 28ice Daniel, we found that if we put the dll under any directory indicated by the PATH environment variable, the effect is the same as that under the system32 directory.
It can also be used.

Besides MYSQL5.1, there is a problem I believe you will often encounter ..
When you create a function

This error occurs. However, our statements are not written incorrectly. The DLL is also kill-free or the server is not installed with the kill software ..
Many people do not understand it here ..

This is because MYSQL 5.1 and later versions have additional restrictions.
The DLL used to create a function can only be placed in the plugin directory of mysql ..
This plug-in directory does not exist by default .. YD, probably to prevent DLL writing to this folder through into dumpfile ..
MYSQL cannot create a directory. If the target directory of into dumpfile does not exist, an error is returned.

It needs to be created manually, but it is a system variable.
I installed MYSQL 5.1.3 on the Virtual Machine for testing. The installation directory is:

Pass:

View source
Print? 1 show variables like % plugin %;


You can see:
+ --------------- + ------------------------------------------------------------------------
| Variable_name | Value
+ --------------- + -------------------------------------------------------------------------
| Plugin_dir | C: Program FilesMySQLMySQL Server 5.1lib/plugin
+ --------------- + -------------------------------------------------------------------------

The plug-in directory is the lib/plug-in under the mysql installation directory, which needs to be created manually.
Upload udf. dll to this location and create a function.

However, the value of this variable is read-only.

View source
Print? 1 set @ plugin_dir = d :\;


Changing its value will cause an error.

You can only add

..
Helpless ..
Therefore, it is necessary to determine the MYSQL version before exporting the UDF permission.

If it is later than 5.1, it will not work. If it is a function created in versions earlier than 5.1, the error Cant open shared library will also be reported.
Check whether the DLL has been exported, or if it has been killed for soft isolation or removal.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.