<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.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://www.jackxiang.com/post//</link>
<title><![CDATA[[个人原创]实践Ok之Python下的Mysql连接模块安装和Linux下通过python 来连接Mysql简单示例,python的Json输出和Memcache模块安装等]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Sat, 22 Jan 2011 02:40:09 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	（1）pyhton shell下导入MySQLdb失败。<br/>http://pypi.python.org/pypi/MySQL-python/#downloads<br/>（2）下载解压MySQL-python。<br/>http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.3.tar.gz#md5=215eddb6d853f6f4be5b4afc4154292f<br/>（3）build时提示缺少setuptools。<br/>root@192.168.1.104:~/software/python/MySQL-python-1.2.3# python setup.py<br/>Traceback (most recent call last):<br/>&nbsp;&nbsp;File &quot;setup.py&quot;, line 5, in &lt;module&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;from setuptools import setup, Extension<br/>ImportError: No module named setuptools<br/><br/>（4）下载安装setuptools。<br/> http://pypi.python.org/pypi/setuptools#downloads 选自己Python对应的版本。<br/>http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg#md5=bfa92100bd772d5a213eedd356d64086<br/>sh setuptools-0.6c11-py2.6.egg<br/><br/>root@192.168.1.104:~/software/python# python<br/>Python 2.6.6 (r266:84292, Jun 18 2012, 14:10:23)<br/>[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2<br/>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br/>&gt;&gt;&gt; import setuptools<br/><br/>上面没有报错说明安装成功了的。<br/>（5）安装 mysql-devel 及其他必要的库<br/>yum install mysql mysql-devel<br/><br/>（6）build mysqldb成功。<br/>cd MySQL-python-1.2.3<br/>/MySQL-python-1.2.3# python setup.py build<br/>实践出现：<br/>在包含自 _mysql.c：29 的文件中:<br/>pymemcompat.h:10:20: 错误：Python.h：没有那个文件或目录<br/><br/>继续执行python setup.py install，可能出现以下错误：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ======&gt; pymemcompat.h:10:20: 致命错误：Python.h：没有那个文件或目录 编译中断。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;出现这个问题的原因是，系统中的python是自带的，而没有安装python的开发包并没有安装，所以在shell下执行如下命令：<br/>点击(此处)折叠或打开<br/>yum install python-devel<br/>Installed size: 454 k<br/>Is this ok [y/N]: y<br/>Installed:<br/>&nbsp;&nbsp;python-devel.i686 0:2.6.6-29.el6_2.2&nbsp;&nbsp;Complete!<br/><br/>&nbsp;&nbsp;再次：<br/>python setup.py build<br/>running build<br/>running build_py<br/>copying MySQLdb/release.py -&gt; build/lib.linux-i686-2.6/MySQLdb<br/>running build_ext<br/><br/>编辑 site.cfg ，把 mysql_config 那一行取消注释，并改为：<br/>mysql_config = /usr/lib64/mysql/mysql_config<br/>python setup.py build<br/>python setup.py install<br/><br/>安装：python setup.py install<br/>...<br/>Finished processing dependencies for MySQL-python==1.2.3<br/><br/><br/>安装结束后，<br/>打开 python2.6 shell， 输入<br/>import MySQLdb&nbsp;&nbsp; (注意：MySQLdb中的y是小写)<br/>如果没够报错就说明安装成功了。<br/><br/>=================================================<br/>示例程序：<br/>首先，确定python-mysql是否已经安装了：<br/>rpm包查看方法：<br/>linux-Jack-nb4:/home/jackxiang/python # rpm -qa&#124;grep python-mysql<br/>python-mysql-1.2.0-17.2<br/>说明系统已经有Python和mysql连接的包了。<br/>如没有该包，需要通过rpm或者包来安装，可能较为麻烦，最好是在系统安装的时候就选择上该rpm包，这样做就很方便。<br/>其次，上Python代码：<br/><br/><br/><div class="code">import MySQLdb <br/>import MySQLdb.cursors <br/>db = MySQLdb.connect(host = &#039;localhost&#039;, user = &#039;root&#039;, passwd = &#039;123456&#039;, db = &#039;mysql&#039;,cursorclass = MySQLdb.cursors.DictCursor) <br/>cursor = db.cursor() <br/>cursor.execute(&#039;select * from user&#039;) <br/>rs = cursor.fetchall() <br/>print rs</div><br/><br/>最后，运行脚本：<br/>python python.py&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>(&#123;&#039;Drop_priv&#039;: &#039;Y&#039;, &#039;Execute_priv&#039;: &#039;Y&#039;, &#039;Create_routine_priv&#039;: &#039;Y&#039;, &#039;Repl_client_priv&#039;: &#039;Y&#039;, &#039;Create_user_priv&#039;: &#039;Y&#039;, &#039;Create_priv&#039;: &#039;Y&#039;, &#039;References_priv&#039;: &#039;Y&#039;, &#039;max_user_connections&#039;: 0L, &#039;Shutdown_priv&#039;: &#039;Y&#039;, &#039;Grant_priv&#039;: &#039;Y&#039;, &#039;max_updates&#039;: 0L, &#039;max。。。。。<br/><br/>体会到Python很简单，很强大吧，呵呵<br/><br/><br/>ython的memcache和json模块：<br/>一般都是：python setup.py build&nbsp;&nbsp;<br/>python setup.py install<br/>Python的Memcache扩展：<br/>ftp://ftp.tummy.com/pub/python-memcached/python-memcached-latest.tar.gz<br/>/python-memcached-1.48# python setup.py&nbsp;&nbsp;build&nbsp;&nbsp;<br/>python-memcached-1.48# python setup.py&nbsp;&nbsp;install<br/><br/>import memcache, import cjson。
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [个人原创]实践Ok之Python下的Mysql连接模块安装和Linux下通过python 来连接Mysql简单示例,python的Json输出和Memcache模块安装等]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>