MySQL 5.1支持触发器以及自定义函数接口(UDF)的特性,如果配合libmemcache以及Memcached Functions for MySQL,就能够实现memcache的自动更新。简单记录一下安装测试步骤。 haohtml.com
安装步骤 网页制作技术网
安装 memcached,这个步骤很简单,随处可见 网页制作技术网
安装mySQL Server 5.1RC,安装办法也很大众,不废话了 网页制作技术网
编译libmemcached,解压后安装即可./configure; make; make install 内容来自haohtml.com
编译 Memcached Functions for MySQL,在http://download.tangent.org/找一个最新的版本下载就是,./configure --with-mysql=/usr/local/mysql/bin/mysql_config --libdir=/usr/local/mysql/lib/mysql/ www.haohtml.com make 内容来自haohtml.com make install www.haohtml.com 接下来有两个办法让Memcached Functions for MySQL在mysql中生效 haohtml.com
在mysql的shell中执行 memcached_functions_mysql源码目录下的sql/install_functions.sql,这会把memcache function作为UDF加入mysql www.haohtml.com
运行memcached_functions_mysql源码目录下的 utils/install.pl,这是一个Perl脚本,作用同上一条 www.haohtml.com 测试memcache function 网页制作技术网 以下测试脚本摘自memcached_functions_mysql的源码目录,有兴趣可以试试 copyright haohtml.com PLAIN TEXTCODE: drop table if exists urls;
create table urls ( id int(3) not null, url varchar(64) not null default '', 网页制作技术网
primary key (id) ); select memc_servers_set('localhost:11211'); select memc_set('urls:sequence', 0); DELIMITER | DROP TRIGGER IF EXISTS url_mem_insert; CREATE TRIGGER url_mem_insert BEFORE INSERT ON urls 内容来自haohtml.com FOR EACH ROW BEGIN SET NEW.id= memc_increment('urls:sequence'); SET @mm= memc_set(concat('urls:',NEW.id), NEW.url); copyright haohtml.com END | DELIMITER ; insert into urls (url) values ('http://google.com'); insert into urls (url) values ('http://www.ooso.net/index.PHP'); insert into urls (url) values ('http://www.ooso.net/'); insert into urls (url) values ('http://slashdot.org'); 内容来自haohtml.com insert into urls (url) values ('http://mysql.com'); select * from urls; select memc_get('urls:1'); select memc_get('urls:2'); haohtml.com select memc_get('urls:3'); select memc_get('urls:4'); select memc_get('urls:5'); |
