In MYSQL, you can use the create function command to call different. so shared library files.
Before compilation, add the following options: -- with-mysqld-ldflags =-rdynamic.
A minor problem occurred during re-compilation, possibly because the system was lost during the upgrade ......
Configure: error: No curses/termcap library found
Solution: sudo apt-get install libncurses5-dev
And then use configure again.
In the SQL folder, there is an instance program udf_example.c file. You can compile the file separately to generate a shared library file:
Gcc-shared-o udf_example.so udf_example.cc-I/usr/local/mysql/include/mysql
In the SQL folder, The udf_example.def file provides the function list:
LIBRARY udf_example
VERSION 1.0:
EXPORTS
Lookup
Lookup_init
Reverse_lookup
Reverse_lookup_init
Metaphon_init
Metaphon_deinit
Metaphon
Myfunc_double_init
Myfunc_double
Myfunc_int_init
Myfunc_int
Sequence_init
Sequence_deinit
Sequence
Avgcost_init
Avgcost_deinit
Avgcost_reset
Avgcost_add
Avgcost_clear
Avgcost
Is_const
Is_const_init
Check_const_len
Check_const_len_init
Specifically, xx_init indicates the loading function, and xx_deinit indicates the unmounting function, which corresponds to the create function AND drop function respectively.
Xx_clear: resets or returns the relevant value to zero.
Xx_add: used together with xx_clear to group.
Modify the configuration file my. cnf
Add the following line to mysqld: plugin_dir =/usr/local/mysql/lib/plugin. All the shared library files are stored in this folder.
Run the udf_example.so file cp in this folder, open the server, and run: mysql> create function metaphon returns string soname "udf_example.so ";
ERROR: ERROR 1127 (HY000): Can't find symbol 'metaphon' in library
The file location in the shared library is correct, and there is no problem with the permissions. I have found a lot on the Internet and have not found the correct answers. I think it may be because an error occurred while compiling the UDF source file, after multiple attempts, the call is successfully compiled in the following format:
Make udf_example.o
Gcc-Wall-shared-DMYSQL_DYNAMIC_PLUGIN udf_example.o-o udf_example.so
Copy udf_example.so to the/usr/local/mysql/lib/plugin folder. The execution is successful:
Mysql> create function metaphon returns string soname "udf_example.so ";
Query OK, 0 rows affected (0.00 sec)