5-11 2,749 views
如果没有安装python mysqldb模块的话会报错,“ImportError: No module named MySQLdb”
"安装python
执行 ~ yum -y install yum install MySQL-python.x86_64
python代码
#!/usr/bin/env python
import MySQLdb
try:
conn=MySQLdb.connect(host='127.0.0.1',user='root',passwd='',db='blog',port=3306)
cur=conn.cursor()
a = cur.execute('select * from blog_user')
#输出
numrows = int(cur.rowcount)
for i in range(numrows):
row = cur.fetchone()
print row
cur.close()
conn.close()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1]
另附(windows下python mysqldb 模块下载地址):http://sourceforge.net/projects/mysql-python/files/mysql-python/[/warning]