Monday 21 December 2009

Using MySQL with memcached

Installing memcached on Centos 5 (x86_64)

$ wget http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

--Install a new RPM server

$ rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

--Now we can simply use yum to install Memcached:
$ yum install memcached

--Starting memcached . Note memcached runs on port 11211

$ memcached -d -u nobody -l 127.0.0.1

--install libmemcached

$ wget http://download.tangent.org/libmemcached-0.35.tar.gz
$ tar -zxf libmemcached-0.35.tar.gz
$ cd libmemcached-0.35
$ ./configure --prefix=/usr/local/memcached
$ make clean && gmake
$ gmake install

--Add following lines into /etc/ld.so.conf

/usr/local/lib
/usr/lib
/usr/lib64/mysql
/usr/local/memcached/lib
/usr/lib64/mysql/lib

-- Creates the necessary links and cache to the most recent shared libraries

$ ldconfig

-- install memcached UDFs
$ wget http://download.tangent.org/memcached_functions_mysql-0.9.tar.gz
$ tar -zxf memcached_functions_mysql-0.9.tar.gz
$ cd memcached_functions_mysql-0.9
$ ./configure --with-mysql=/usr/bin/mysql_config --libdir=/usr/lib64/mysql --with-libmemached=/usr/local/memcached/lib
$ make clean && gmake
$ gmake install

-- Once this is done, initialize memcached functions with MySQL.

shell# cd sql
shell# echo install_functions.sql | mysql

-- Connect to MySQL

mysql> SELECT memc_servers_set('127.0.0.1:11211');
mysql> SELECT memc_set('mykey', 'Getting this with SELECT means all works well');
+--------------------------------------------------------------------+
| memc_set('mykey', 'Getting this with SELECT means all works well') |
+--------------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------------+
1 row in set (0.03 sec)

mysql> SELECT memc_get('mykey');
+-----------------------------------------------+
| memc_get('mykey') |
+-----------------------------------------------+
| Getting this with SELECT means all works well |
+-----------------------------------------------+
1 row in set (0.00 sec)

No comments:

Post a Comment