志當存高遠,功到自然成!

          少年強則中國強,少年進步則中國進步!

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            53 Posts :: 2 Stories :: 2 Comments :: 0 Trackbacks
          mysql 5.1支持觸發(fā)器以及自定義函數(shù)接口(UDF)的特性,如果配合libmemcache以及Memcached Functions for MySQL,就能夠實現(xiàn)memcache的自動更新。簡單記錄一下安裝測試步驟。

            mysql 5.1支持觸發(fā)器以及自定義函數(shù)接口(UDF)的特性,如果配合libmemcache以及Memcached Functions for MySQL,就能夠實現(xiàn)memcache的自動更新。簡單記錄一下安裝測試步驟。

            安裝步驟

            安裝memcached,這個步驟很簡單,隨處可見。安裝mysql server 5.1RC,安裝辦法也很大眾,不廢話 了。

            編譯libmemcached,解壓后安裝即可./configure; make; make install

            編譯Memcached Functions for MySQL,在http://download.tangent.org/找一個最新的版本下載就 是,./configure --with-mysql=/usr/local/mysql/bin/mysql_config -- libdir=/usr/local/mysql/lib/mysql/

            make

            make install

            接下來有兩個辦法讓Memcached Functions for MySQL在mysql中生效。

            在mysql的shell中執(zhí)行memcached_functions_mysql源碼目錄下的sql/install_functions.sql,這會 把memcache function作為UDF加入mysql。

            運行memcached_functions_mysql源碼目錄下的utils/install.pl,這是一個perl腳本,作用同上一 條。

            測試memcache function。

            以下測試腳本摘自memcached_functions_mysql的源碼目錄,有興趣可以試試。


          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
          FOR EACH ROW BEGIN
          SET NEW.id= memc_increment('urls:sequence');
          SET @mm= memc_set(concat('urls:',NEW.id), NEW.url);
          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');
          insert into urls (url) values ('http://mysql.com');
          select * from urls;
          select memc_get('urls:1');
          select memc_get('urls:2');
          select memc_get('urls:3');
          select memc_get('urls:4');
          select memc_get('urls:5');
          主站蜘蛛池模板: 瑞丽市| 和硕县| 镇赉县| 阿拉尔市| 桑植县| 特克斯县| 黄平县| 旌德县| 南宫市| 安顺市| 固安县| 鹿邑县| 濮阳县| 松滋市| 荥经县| 武穴市| 东莞市| 昌邑市| 饶阳县| 天水市| 镇雄县| 紫阳县| 于都县| 天气| 荔浦县| 行唐县| 会宁县| 盐城市| 台中县| 武威市| 绥棱县| 新津县| 留坝县| 长泰县| 定安县| 元朗区| 金秀| 巴林左旗| 德兴市| 襄城县| 祁门县|