Ran into an interesting issue earlier tonight where a customer wanted the levenshtein UDF module (user defined functions) compiled for mysql on a centos5 64 bit box. While it seemed the module built correctly, he was still getting errors in trying to create and use the functions:

mysql> CREATE FUNCTION levenshtein RETURNS INT SONAME ‘libmysqllevenshtein.so’;
ERROR 1026 (HY000): Error writing file ‘mysql.func’ (errno: 121)

mysql> select levenshtein(‘abc’, ‘bbc’);
ERROR 1547 (HY000): Column count of mysql.proc is wrong. Expected 20, found 16. The table is probably corrupted

After some poking around, this is what was done that ultimately led to a successful implementation of this module:

wget http://joshdrew.com/mysql_levenshtein_udf-1.0.tar.gz

tar -xzvf mysql_levenshtein_udf-1.0.tar.gz

gcc -I/usr/include/mysql -fPIC -O -pipe -o mysqllevenshtein.so -shared \
-L/usr/lib64/mysql -lmysqlclient mysqllevenshtein.cc

cp mysqllevenshtein.so /usr/lib64/libmysqllevenshtein.so

Once that module is in place, restart mysql and log into it. If it is loading correctly, you should be able to do the following:

mysql> CREATE FUNCTION levenshtein RETURNS INT SONAME ‘libmysqllevenshtein.so’;

mysql> select levenshtein(‘abc’, ‘bbc’);
| levenshtein(‘abc’, ‘bbc’) |
| 1 |
1 row in set (0.01 sec)

The ultimate key here was using the correct libs, since most of the instructions out there on the net (due to the age of this module) assume 32bit. The resulting module, when compiled the way those instructions indicated, would load but not be functional. The above resolved the problem. I figured I’d document this here for others that are trying to compile it and having issues, in case it saves them some time. I’m always happy when folks try to do things themselves and am a little sad when the documentation for a given software fails them somewhat. The difference in libs may seem like a no-brainer to some, but for those just learning… well. Let’s put this out there in case it helps the next guy. 🙂

Category: linux, mysql

2 Responses to Levenshtein UDF on a 64bit OS

  1. nevvermind says:

    What server of yours I have to crash to get my hands on that juicy 64*.so of yours? I’m going nuts here with this blasted architecture. AKA: I couldn’t compile it (because I’m somewhat of a newb) – well, actually I did, but I get that ELFCLASS32 error, so I’m guessing it’s still 32bit.

  2. alex says:

    Did you get it sorted out? It all really boils down to making sure you point at the right library files: -L/usr/lib64/mysql

Leave a Reply


gives good tech

Kale is one of the smartest people I know

Racker Hacker
Major is always good for leet deetz