Friday, April 2, 2010

[Level 3] Install memcached user defined function for MySQL on CentOS 5.4

Memcaced is a good solution for scale out your system.
And there is a project for MySQL udf by implement memcached.

Prepare libmemcached:
# wget http://download.tangent.org/libmemcached-0.37.tar.gz
# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# ./configure --with-mysql=/usr/local/mysql/bin/mysql_config
# make && make install
PS. when I use libmemcached 0.38 and complie source, I get a error like below:
# wget http://download.tangent.org/memcached_functions_mysql-0.8.tar.gz
servers.c: In function 'memc_servers_set':
servers.c:122: error: 'memcached_st' has no member named 'hosts'
servers.c:123: error: 'memcached_st' has no member named 'hosts'
servers.c:124: error: 'memcached_st' has no member named 'hosts'
But after down-grade the version from 0.38 to 0.37 then works.

Compile memcahced function:
# wget http://download.tangent.org/memcached_functions_mysql-0.8.tar.gz
# tar zxvf ./memcached_functions_mysql-0.8.tar.gz
# cd ./memcached_functions_mysql-0.8
# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig 
# ./configure
# make && make install

Check MySQL plugin folder:
mysql> show variables like 'plugin_dir';
+---------------+-----------------------------------+
| Variable_name | Value                             |
+---------------+-----------------------------------+
| plugin_dir    | /usr/local/mysql/lib/mysql/plugin |
+---------------+-----------------------------------+
1 row in set (0.00 sec)
mysql>

Copy library to MySQL plugin folder:
# cp libmemcached_functions_mysql.* /usr/local/mysql/lib/mysql/plugin/

Create UDF:
mysql> source ./sql/install_functions.sql;
ERROR 1126 (HY000): Can't open shared library 'libmemcached_functions_mysql.so' (errno: 22 /usr/local/mysql/lib/mysql/plugin/libmemcached_functions_mysql.so: undefined symbol: memcached_string_append)
ERROR 1126 (HY000): Can't open shared library 'libmemcached_functions_mysql.so' (errno: 22 /usr/local/mysql/lib/mysql/plugin/libmemcached_functions_mysql.so: undefined symbol: memcached_string_append)
...
mysql>
Create UDF Fail...


So I try to use another project called "Drizzle"
# wget http://protobuf.googlecode.com/files/protobuf-2.3.0.tar.gz
# tar zxvf ./protobuf-2.3.0.tar.gz
# cd protobuf-2.3.0
# ./configure && make && make install

# wget http://launchpad.net/libdrizzle/trunk/0.8/+download/libdrizzle-0.8.tar.gz
# tar zxvf ./libdrizzle-0.8.tar.gz
# cd ./libdrizzle-0.8
# ./configure && make && make install

# wget ftp://ftp.pbone.net/mirror/ftp.rpmhelp.net/pub/releases/1.0-CURRENT/SRPMS/pcre-4.3-6sls.src.rpm
# cd /usr/src/redhat/SOURCE
# bzip2 -cd ./pcre-4.3.tar.gz | tar xvf -
# cd ./pcre-4.3
# ./configure && make & make install

# wget http://launchpad.net/drizzle/cherry/2010-03-29/+download/drizzle-2010.03.1412.tar.gz
# tar zxvf ./drizzle-2010.03.1412.tar.gz
# cd ./drizzle-2010.03.1412
# ./configure --with-libprotobuf-prefix=/usr/local/lib --with-libdrizzle-prefix=/usr/local/lib

[ To Be Continue... ]

Wish this helps.

regards,
Stanley Huang