---
title: "ubuntu环境 mysql memcached udf  完整安装（附下载链接）"
author: "asyty"
date: "2012-03-07T13:43:44Z"
tags: []
categories: ["开源软件"]
slug: "ubuntu-mysql-memcached-udf"
draft: false
lastmod: "2012-04-25T14:45:05Z"
id: 1442587
url: "https://asyty.iteye.com/blog/1442587"
---

昨天折腾了很久的memcached udf的安装，编译安装时出现各种报错，主要是各版本的不兼容引起的。

 

最后成功安装，以下是安装好的各种版本，按照安装顺序如下

 

[mysql-5.5.21.tar.gz](http://dev.mysql.com/downloads/mysql/#downloads)

 

[libevent-2.0.17-stable.tar.gz](http://libevent.org/)

 

[memcached-1.4.13.tar.gz](http://memcached.org/)

 

[libmemcached-0.34.tar.gz](https://launchpad.net/libmemcached/+download)

 

[memcached\_functions\_mysql-1.1](https://launchpad.net/memcached-udfs) 

闲的蛋疼修改了下1.1的源码，兼容libmemcached-1.0.x，见[http://asyty.iteye.com/blog/1497468](/blog/1497468)

 

mysql安装见 [http://asyty.iteye.com/blog/1442503](/blog/1442503)

 

安装memcached必须先安装libevent

 

**安装libevent**

 

tar -zvxf libevent-2.0.17-stable.tar.gz 

 

cd libevent-2.0.17-stable

 

./configure --prefix=/usr

 

make && make install

 

查看是否安装成功 ls /usr/lib | grep libevent

 

 

**安装memcached**

 

 

tar -zxvf memcached-1.4.13.tar.gz 

cd memcached-1.4.13

 

./configure --prefix=/usr/local/ --with-libevent=/usr

 

make && make install

 

查看是否安装成功 ls /usr/local/bin/ | grep memcached

 

尝试启动memcached

/usr/local/bin/memcached -d -m 10 -u root -l 127.0.0.1 -p 20000 -c 256 -P tmp/memcached.pid

telnet连接20000端口，查看memcached 状态

telnet 127.0.0.1  20000

//出现以下的信息

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is '^]'.

输入 stats 查看状态信息

**安装libmemcached**

要使用udf，必须安装libmemcached，这个比较恶心，尝试了很多很多版本，从0.38~最新的1.04，后面安装**memcached\_function\_mysql**均出现各种不同的报错，例如 

servers.c:263:28: error: ‘memcached\_st’ has no member named ‘hosts’servers.c:264:28: error: ‘memcached\_st’ has no member named ‘hosts’

最后使用0.34版，据说0.37 0.36等等也没问题（后来试了下0.37编译没问题，但是和memcached\_functions\_mysql-1.1后面会出问题）

tar -zxvf libmemcached-0.34.tar.gz

cd libmemcached-0.34

./configure --with-memcached=/usr/local/bin/memcached

make

make install

**安装 memcached\_function\_mysql**

tar -zxvf memcached\_functions\_mysql-1.1.tar.gz 

cd memcached\_functions\_mysql-1.1

./configure --prefix=/usr/local/memcached\_mysql --with-mysql=/usr/local/mysql/bin/mysql\_config --with-libmemcached=/usr/local

//指定libmemcached的目录，不然会报libmemcached not found

make && make install

将/usr/local/memcached\_mysql/lib下的文件复制到mysql的lib中

sudo cp /usr/local/memcached\_mysql/lib/libmemcached\_functions\_mysql.* /usr/local/mysql/lib/plugin/

同时，在mysql中添加udf函数，在解压的memcached\_functions\_mysql-1.1安装包文件夹下的/sql文件夹下，有两个sql文件，启动mysql服务并连接，在mysql中运行

mysql&gt; use xxx // use某个database

mysql&gt; source /xxxx/memcached\_functions\_mysql-1.1/sql/install\_functions.sql  //(这一步，0.37的libmemcached会出问题，函数对应不上)

mysql&gt; source /xxxx/memcached\_functions\_mysql-1.1/sql/trigger\_fun.sql

mysql&gt; select * from mysql.func;  //查看导入的函数

就大功告成！！如果make install过程中报错说没有权限访问啥啥的，就用 sudo make install 或者通过 sudo su root 切换到root用户吧。。。 

### 转载请注明源 [http://asyty.iteye.com/blog/1442587](/blog/1442587)