1. 程式人生 > >python 2.7 連線

python 2.7 連線

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