python怎么连接sqlserver
1. Python连接mssql
ubuntu linux上
1.1
sudo apt-get install python
1.2 重启终端
1.3

sudo apt-get --assume-yes update
sudo apt-get --assume-yes install freetds-dev freetds-bin
sudo apt-get --assume-yes install python-dev python-pip
sudo pip install pymssql

1.4
sudo vi /etc/freetds/freetds.conf
2.安装pyodbc
2.1 为了解决pyodbc.h:52:17: fatal error: sql.h: No such file or directory

sudo yum install unixODBC-devel.x86_64
然后:
sudo pip install pyodbc
2.2 安装MSSQL native client
2.3

编写Python程序:
import pyodbc
conn = pyodbc.connect('DRIVER={SQL Server Native Client 11.0};
SERVER=aaaa; UID=bbbb; PWD=ccc; DATABASE=ddd; Encrypt=yes;
TrustServerCertificate=no');
cursor = conn.cursor()
cursor.execute("select count(distinct d) as cnt from ddddd6 where day_id=20160531")
row = cursor.fetchone()
while row:
print str(row[0])
row = cursor.fetchone()

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐