<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post/4801/</link>
<title><![CDATA[将MySQL数据映射到Memcached]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Thu, 17 Nov 2011 05:35:18 +0000</pubDate> 
<guid>http://jackxiang.com/post/4801/</guid> 
<description>
<![CDATA[ 
	<br/>1. 安装memcached<br/>tar zxvf libevent-1.2.tar.gz<br/>cd libevent-1.2<br/>./configure –prefix=/usr<br/>make<br/>make install<br/>tar zxvf memcached-1.2.0.tar.gz <br/>cd memcached-1.2.0<br/>./configure --prefix=/usr/local/memcached --with-libevent=/usr<br/>make<br/>make install<br/><br/>2. 启动memcached<br/>/usr/local/memcached/memcached -d -m 100 -p 11211 -u root<br/>如果出错，则执行：<br/>ln -s /usr/local/lib/libevent-1.2.so.1 /lib/libevent-1.2.so.1<br/><br/>3. 安装memcache的php扩展<br/>tar vxzf memcache-2.2.1.tgz<br/>cd memcache-2.2.1<br/>/usr/local/php/bin/phpize<br/>./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir<br/>make<br/>make install<br/>上述安装完后会有类似这样的提示：<br/>Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/<br/>把php.ini中的extension_dir = &#039;./&#039;修改为<br/>extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”<br/>添加一行来载入memcache扩展：extension=memcache.so<br/><br/>4. 安装libmemcached和memcached_functions_mysql<br/>wget http://download.tangent.org/libmemcached-0.42.tar.gz<br/>wget http://download.tangent.org/memcached_functions_mysql-0.9.tar.gz<br/>tar zxvf libmemcached-0.42.tar.gz<br/>tar zxvf memcached_functions_mysql-0.9.tar.gz<br/>cd libmemcached-0.42<br/>./configure --prefix=/usr/local/libmemcached/ --with-memcached=/usr/local/memcached/bin/memcached<br/>make<br/>make install<br/>如果出错，可执行：<br/>./configure --prefix=/usr/local/libmemcached/ --with-memcached=/usr/local/memcached/bin/memcached --disable-64bit CFLAGS=&quot;-O3 -march=i686&quot;<br/><br/>cd memcached_functions_mysql-0.9<br/>./configure --with-mysql=/usr/bin/mysql_config --libdir=/var/lib/mysql&nbsp;&nbsp;--with-libmemcached=/usr/local/libmemcached<br/>make<br/>make install<br/>如果出错，可执行：<br/>ln -s /usr/local/libmemcached/lib/libmemcached.so /lib/libmemcached.so<br/>ln -s /usr/local/libmemcached/lib/libmemcached.so.5 /lib/libmemcached.so.5<br/>或者重装libmemcached，换一个较低的版本(例如：libmemcached-0.30.tar.gz)<br/><br/>5. 进行映射<br/>mysql -hlocalhost -uroot -p<br/>将UDFs加载到MySQL中：<br/>create function memc_servers_set returns int soname &quot;libmemcached_functions_mysql.so&quot;;<br/>create function memc_set returns int soname &quot;libmemcached_functions_mysql.so&quot;;<br/>create function memc_get returns string soname &quot;libmemcached_functions_mysql.so&quot;;<br/>create function memc_delete returns string soname &quot;libmemcached_functions_mysql.so&quot;;<br/>如果出错，可执行：<br/>ln -s /var/lib/mysql/libmemcached_functions_mysql.so /lib/libmemcached_functions_mysql.so<br/><br/>测试UDF是否安装成功：<br/>先添加Memcached，可以添加多台<br/>select memc_servers_set(&#039;127.0.0.1:11211&#039;);<br/>select memc_set(&#039;libing&#039;, &#039;roast&#039;);<br/>select memc_get(&#039;libing&#039;);<br/><br/>6. 进行测试<br/>mysql -hlocalhost -uroot -p<br/>create table mctest(`key` int, `value` varchar(100));<br/>create trigger mysqlmmc before insert on mctest for each row set @tmp = memc_set(NEW.key, NEW.value);<br/>show triggers;<br/><br/>select memc_servers_set(&#039;127.0.0.1:11211&#039;);<br/><br/>insert into mctest values(9, &#039;roast&#039;);<br/>select memc_get(&#039;9&#039;);<br/>select * from mctest;<br/><br/>telnet 127.0.0.1 11211<br/>get 9<br/><br/>7. 程序测试<br/><textarea name="code" class="html" rows="15" cols="100">
&lt;?
// 向数据库插入数据
$num = rand(1, 100);
$conn = mysql_connect(&quot;127.0.0.1&quot;, &#039;root&#039;, &#039;MySql&#039;) or die (&#039;connect error : &#039; . mysql_error());
mysql_select_db(&#039;qianbao&#039;, $conn) or die (&quot;Can&#039;t use qianbao : &quot;. mysql_error());
$sql = &quot;insert into mctest values(&quot;.$num.&quot;, &#039;this is a tset : &quot;.$num.&quot;&#039;)&quot;;
echo &quot;SQL : &quot;.$sql.&quot;&lt;br&gt;&quot;;
$result = mysql_query($sql) or die (&quot;query error : &quot;. mysql_error());

// 从MC读数据
$memcache = new Memcache;
$memcache-&gt;connect(&#039;localhost&#039;, 11211) or die (&quot;Could not connect&quot;);
$get_value = $memcache-&gt;get($num);
echo &quot;MC : &quot;.$get_value;
?&gt;
</textarea><br/><br/>参考：http://www.cnblogs.com/cy163/archive/2009/08/12/1544143.html
]]>
</description>
</item><item>
<link>http://jackxiang.com/post/4801/#blogcomment63381</link>
<title><![CDATA[[评论] 将MySQL数据映射到Memcached]]></title> 
<author>李彦宏 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 26 Nov 2011 12:32:37 +0000</pubDate> 
<guid>http://jackxiang.com/post/4801/#blogcomment63381</guid> 
<description>
<![CDATA[ 
	学习了 厉害啊
]]>
</description>
</item>
</channel>
</rss>