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()

猜你喜欢

转载自blog.csdn.net/haogeoyes/article/details/83995605