MySQL-python 安装

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()
原文地址:https://www.cnblogs.com/linn/p/3858630.html