9394952

导航

Linux下安装pymssql(转)

原文地址:https://blog.51cto.com/hezun/1745045

 

安装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

tar -zxvf pymssql-2.1.0.tar.gz

cd pymssql-2.1.0


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()
-----------------------------------
©著作权归作者所有:来自51CTO博客作者hezun的原创作品,请联系作者获取转载授权,否则将追究法律责任
Linux下安装pymssql及简单尝试
https://blog.51cto.com/hezun/1745045

posted on 2022-08-15 16:33  9394952  阅读(398)  评论(0编辑  收藏  举报