1. 程式人生 > >python 連線其他電腦上的資料庫

python 連線其他電腦上的資料庫

首先,自己電腦中要安裝 MySQL-python,我電腦配置為python2.7.6, windows64bit

下載安裝後,在python檔案中新增如下程式碼:

#匯入資料庫包
import MySQLdb

#資料庫連線,括號中依次是你要連線資料庫所在的電腦ip, 使用者名稱,密碼,資料庫名稱:
con = MySQLdb.connect(host = '192.168.0.197',user = 'dev', passwd = 'dev', db = 'db_avsc')
cursor = con.cursor()
sql = 'select * from t_offers'
offer_data = cursor.execute(sql)

這樣即可使用其他電腦上的資料庫