https://pypi.python.org/pypi/MySQL-python/1.2.5

wget https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip --no-check-certificate

 

测试代码

# -*- coding: utf-8 -*-
import sys
import MySQLdb
import json
conn = None
try:
    conn = MySQLdb.connect(host = '10.20.1.1', user = 'test' ,passwd='123456', port = 3306, charset = 'utf8', db='test')
    cur = conn.cursor()
    # cur.execute("select * from user where name=%s", "hehe")
    cur.execute("select * from user where user_name='test'")
    row = cur.fetchone()
    if row != None:
        str = row[1]
        # 返回用户所属项目
        newStr = str.split(',')
        for s in newStr:
            print s
            
    cur.close()
finally:
    if conn:
        conn.close()
posted on 2014-07-21 16:07  凌度  阅读(293)  评论(0编辑  收藏  举报