python 2.7 连接mysql

sudo pip  install  MySQL-python

# import xlrd
import MySQLdb.cursors
conn=MySQLdb.connect(host='ip',
                    user='user',
                    passwd='password',
                    db='db name',
                    charset='utf8') 
    cursor = conn.cursor()        
    cursor.execute ("select * from tablename")
    row = cursor.fetchall()
    cursor.close()  
    conn.close()

你可能感兴趣的:(python)