1、安裝資料庫驅動:
mysql的驅動是MySQLdb【http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/】, 微軟sql的驅動是pymssql, 直接去pypi網站下就可以了
windows下安裝MySQLdb可以參考這個連結:
http://www.byywee.com/page/M0/S587/587000.html,或者直接下載這個檔案,所有東西和說明都已經在一起了:http://vdisk.weibo.com/s/7LJqS
2、測試
import MySQLdb as mysql def test_mysql():conn = mysql.connect(host='10.255.254.208',user='writeuser',passwd='password',db='myDB') cur = conn.cursor() sql = 'select product_id, is_share_product from Products_Core where is_share_product=1 and product_id>10000 limit 1,10;' cur.execute(sql) print cur.fetchall() cur.close() conn.close() import pymssql def test_mssql():conn=pymssql.connect(host="10.255.254.207",user="writeuser",password="password",database="Account") cur=conn.cursor() sql = 'SELECT TOP (10) money_id, cust_id FROM my_money'cur.execute(sql) print cur.fetchall() cur.close() conn.close if __name__ == "__main__":test_mysql()test_mssql()