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