标签:server database password python xxxxxx
安装pymssql模块:
centos :
yum install python-devel python-setuptools
去https://pypi.python.org/pypi/pymssql/2.1.0 下载源码包 wget https://pypi.python.org/packages/source/p/pymssql/pymssql-2.1.0.tar.gz#md5=e955442a8cd43456cdf5c28b75147afb
yum install freetds-devel
python setup.py build
python setup.py install
一定要装freetds-devel ,不然编译会报gcc的错。
正确编译以后应该可以在python 中import pymssql。
window版下载地址:
https://pypi.python.org/pypi/pymssql/2.1.1#downloads
#!/usr/bin/python
import pymssql,sys
conn = pymssql.connect(server=‘192.168.1.252‘,port=‘1433‘,user=‘sa‘,password=‘xxxxxx‘,database=‘xxxx‘, charset=‘UTF-8‘)
print ‘connect ok....‘
cursor = conn.cursor()
sql = ‘select count(*) from sys.dm_exec_connections‘
cursor.execute(sql)
row = cursor.fetchone()
print (row[0])
conn.close()
标签:server database password python xxxxxx
原文地址:http://hezun.blog.51cto.com/1137078/1745045